1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 [SOLVED] Screenshots? (How do I work that in?)

Discussion in 'Programming' started by Dr_Nomz, May 19, 2019.

  1. Dr_Nomz

    Dr_Nomz Member

    Joined:
    Oct 31, 2016
    Posts:
    644
    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?
     
    EvanSki likes this.
  2. Danei

    Danei Member

    Joined:
    Mar 23, 2018
    Posts:
    278
    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.
     
  3. EvanSki

    EvanSki King of Raccoons

    Joined:
    Apr 17, 2018
    Posts:
    581
    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: May 20, 2019
    Dr_Nomz likes this.
  4. Dr_Nomz

    Dr_Nomz Member

    Joined:
    Oct 31, 2016
    Posts:
    644
    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: May 20, 2019
  5. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    765
    I wonder who your alt account is...
     
  6. Dr_Nomz

    Dr_Nomz Member

    Joined:
    Oct 31, 2016
    Posts:
    644
    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
     
  7. EvanSki

    EvanSki King of Raccoons

    Joined:
    Apr 17, 2018
    Posts:
    581
    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

    in a create event set num = 0; or in object variables

    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

    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 likes this.
  8. Dr_Nomz

    Dr_Nomz Member

    Joined:
    Oct 31, 2016
    Posts:
    644
    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?
     

Share This Page