• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Having Trouble with Saving...

B

baconlovar

Guest
I've been trying to figure out how to save for hours now...
I've tried:

game_save();
&
if(file_exists("Save.sav")){ file_delete("Save.sav");}
var SaveFile = file_text_open_write("Save.sav");
file_text_open_write("Save.sav");
var SavedRoom = global.levelcounter;
file_text_write_real(SaveFile,SavedRoom);
file_text_close(SaveFile);

now, the weird thing that is happening is that the compiler is like "ignoring" it?
Like, it doesn't crash but it doesn't even respond to the code.
The compiler only says something about:
"Pause event has been registered for this frame
Pause event has been unregistered"

If someone could give me a hand it would be greatly appreciated
 
C

Christian

Guest
Hello, I helped another user with saving and loading not too long ago. Might want to take a look and see if it helps.
https://forum.yoyogames.com/index.php?threads/save-load.5757/#post-41816

The fact that the compiler would be ignoring it sounds a little strange. If it is infact ignoring it, throw a message in there, just to see if it executes. Add this before your if statements
Code:
show_message("This part has executed")
Run the game. If the message shows, move it to the next spot, and to the next spot, keep doing it until it doesn't show. That's where the compiler is missing or ignoring. That would help with debugging.

As for the "Pause event has been registered for this frame. Pause event has been unregistered" This will always happen if you leave the window and come back to it. It's normal behavior but it won't break a game. You can test this by running your game, then while the game is open. Open your web browser, now come back to your game/Gamemaker, you''ll see that same message.
 
B

baconlovar

Guest
Okay so, I actually read your post before but I thought I would try it again. It's so weird, I literally put the show_message function before and after every spot and it kept coming up with the message. So the code like "works" but like I said it's just ignoring it! Could it be my anti-virus? (I have AVG) Do I need to revert/update my gm client? I have no idea this is very odd.

BTW: thanks for the response
 
C

Christian

Guest
The compiler won't show every action that you do unless you tell it to. Only the registration events and critical events.

Assuming you're on Windows, you can find your save file and see what's put in there. Follow these steps to get to your save file
1.) Open Control Panel > Appearance & Personalization
2.) Under "Folder Options", select Show Hidden Folders and Files
3.) Navigate down the list to find where it says Hidden Files and Folders, make sure "Show Hidden Folders, Files and Drives" is checked.
4.) Click Apply, Then you can close out of all of that.
5.) Open the Start Menu (The flag icon on the bottom left)
6.) Type in:
Code:
%appdata%
then press enter.
7.) It should default you into the Roaming folder, go up a level into the parent folder (Appdata)
8.) Click on Local
9.) There should be a folder in here named after your gamemaker project. Open that folder.
10.) You should be able to see your save file here. (If you don't keep this window open, and try to save your game).
11.) To see the contents of the save file, right click on it, and open it with some kind of text editing program (I prefer notepad++, but it doesn't matter which you use).

Now I created a very blank project and I was able to get it to work by doing this
In obj_test > Create Event
Code:
levelcounter = 147; //Simulating the global variable in your code. You won't need this,
obj_test > Left Pressed Event
Code:
if(file_exists("Save.sav")){
    file_delete("Save.sav");
}

/*var*/ SaveFile = file_text_open_write("Save.sav");
//file_text_open_write("Save.sav");

var SavedRoom = levelcounter;

file_text_write_real(SaveFile,SavedRoom);

file_text_close(SaveFile);
I ran the code, and I see the Save file. The compiler window won't reflect it, and this is normal behavior since this is a non-critical event.
 

Tsa05

Member
^ Yep. To get the compiler to output stuff, use show_debug_message(). (Be careful about using in the step event--too many messages can crash the console window).

So, after you write the save file, you could put:
if( file_exists("Save.sav") ){ show_debug_message("Save file exists"); }
 

Yal

šŸ§ *penguin noises*
GMC Elder
In your first example, you don't provide a file name to game_save, so chances are it does nothing (or throw an 'incorrect number of arguments' error). In your second example, you try to open the same file twice in a row, and chances are the second time - which overwrites the file access index - fails because the file is already open, and this could screw up the file access index (SaveFile) so that you can't access the file anymore (if it doesn't outright throw a 'file can't be opened for reading' error, which I'd assume).
 
Top