• 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!

GML Saving And Loading Help

D

derp556

Guest
Hi! I'm a bit inexperienced with saving and loading things, the tutorials online i watch and do 100% as they do, but the game acts like i did nothing after writing the code (No errors, but nothing in the console or noticeable changes) Can someone help me, i just need something that can save variables (After Closing and re-opening) and that is about it
 
U

Ukaygee

Guest
Try this for saving a variable:
Code:
ini_open("savedata.ini");
ini_write_real("save","score",score);
ini_close();
To read the file, try:
Code:
ini_open("savedata.ini");
score = ini_read_real("save","score",0);
ini_close();
You can read more about ini files here
 
D

derp556

Guest
It works, but how would i go about saving global variables? Instead of score
 

NeoShade

Member
Exactly the same way...

Code:
ini_open("savedata.ini");
ini_write_real("save", "score", global.myscore);
ini_close();
 

Pfap

Member
I had a pretty silly mistake when I first started using the ini save functions. I would write some save data like this:
Code:
ini_write_real("Save", "Player", global.signed_up);
The above saves the value of global.signed_up under "Player" in my ini file.
But then would try to load or read it like this:

Code:
 ini_read_real("Save", "Player", global.signed_up);
the third argument to the above function is a default and I can't remember what the exact issue was, but for some reason it was setting it back to my original empty string (even though I assumed there was data under "player".

This is what it should have been:
Code:
sign_save = ini_read_real("Save", "Player", 0);
global.signed_up = sign_save;
This reads the value saved under "Player" into my variable sign_save.
 
Top