Legacy GM [SOLVED] Screenshots? (How do I work that in?)

Dr_Nomz

Member
Remember when you could just press a button and game maker would automatically take a screen shot and save it somewhere? Can it still do that? And how would I work that into my game? Can I decide the folder location for the screenshots as well?
 
D

Danei

Guest
I'm not sure about any built-in functionality, but you can use surface_save() to save a surface (for example the application surface) to disk as a .png, and you can decide where it goes, within the general limitations of GMS's file sandboxing.
 

Evanski

Raccoon Lord
Forum Staff
Moderator
Yeah theres a built in function for screenshots, i'll post the code here later as of when I write this im at work (4:20pm EST)

I slap this in a key press event, but the function is Screen_Save
Code:
{
    do
    {
        //check to see if there is already a png
        if (file_exists(working_directory + "\\ScreenShots\\Screen_"+string(num)+".png"))
        {
            //if there is add one to the number until there isnt one
            num += 1;
        }
    }
    until (!file_exists(working_directory + "\\ScreenShots\\Screen_"+string(num)+".png"))
}

if (!file_exists(working_directory + "\\ScreenShots\\Screen_"+string(num)+".png"))
{
    //save the png
    screen_save(working_directory + "\\ScreenShots\\Screen_"+string(num)+".png")
    //add to the number for a future png
    show_message("saved"+string(num))
    num += 1;
}
 
Last edited:

Dr_Nomz

Member
I'll look into working that into my game, but what's up with the top lines of code? Is there an if check missing, or would that not be there in a normal key press event? Also what about the "do" function, is that necessary?

EDIT: Yeah that first curly brace threw up an error in the code editor lol. I removed it and it LOOKS fine so far, haven't tested in game.

EDIT2: Just tested, threw up an error because "num" wasn't defined. Though setting it to 1 in the create event did fix this, but then when I went to take the screenshot it saved 2 of them for some reason, probably because I need to set it to 1. Is that right? Let me know if it's not.

EDIT3: Just set the value to 0 on NUM, still creates two screenshots per keypress.

EDIT4: Also just found the screenshots folder, it works really well, thank you! :D But what about the other things I just mentioned, like the double screenshot error?
 
Last edited:

Dr_Nomz

Member
Wait, nevermind somehow I copied the second part of the code, wtf that was dumb of me. xD

Well it works perfectly! Code's great, functionality is there. THANK you! :D
 

Evanski

Raccoon Lord
Forum Staff
Moderator
EDIT: Yeah that first curly brace threw up an error in the code editor lol. I removed it and it LOOKS fine so far, haven't tested in game.
Its apart of the Do function as shown in the manual https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml language overview/401_10_do.html

EDIT2: Just tested, threw up an error because "num" wasn't defined. Though setting it to 1 in the create event did fix this, but then when I went to take the screenshot it saved 2 of them for some reason, probably because I need to set it to 1. Is that right? Let me know if it's not.
in a create event set num = 0; or in object variables

EDIT3: Just set the value to 0 on NUM, still creates two screenshots per keypress.
make sure its on a key_release event, other then that it shouldnt make two of them unless youve pressed it twice before one png was done saving, it takes a second to save the actual png after the code runs

EDIT4: Also just found the screenshots folder, it works really well, thank you! :D
No problem! I coded it myself because I wanted a screenshot function, and then realized without any special code it will just overwrite the same png over and over.

The "\\ScreenShots\\" is the folder you want it in, by default it writes in the %appdata% (Working_directory) folder because game maker hates writing files anywhere else

Code:
{ //<-- apart of the do function as defined in the manual
    do
    {
        //check to see if there is already a png, checks to see if theres a file named the value of num if there is up num until there isnt
        if (file_exists(working_directory + "\\ScreenShots\\Screen_"+string(num)+".png"))
        {
            //if there is add one to the number until there isnt one
            num += 1;
        }
    }
    until (!file_exists(working_directory + "\\ScreenShots\\Screen_"+string(num)+".png"))
    //it does this check until it can create a file with the value of num
}

//This is it acutally saving it
if (!file_exists(working_directory + "\\ScreenShots\\Screen_"+string(num)+".png"))
{
    //save the png
    screen_save(working_directory + "\\ScreenShots\\Screen_"+string(num)+".png")
    //add to the number for a future png
    show_message("saved"+string(num))
    num += 1;
}
 

Dr_Nomz

Member
Thanks, but I already figured it out lol. For some reason I pasted the code twice. :p

What about Key_Pressed? That's what I'm using and it seems to work fine, does it need to be released for any reason, or will it work just as fine like this?
 
Top