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

Save and load problems

N

Nexusrex

Guest
Hello, i've been trying to make a little save and load system in my game.
I've been using this code:
Code:
//Loading script
if file_exists("save.ini")
{
ini_open("save.ini");
//Insert variables here vvv
global.beatedonce = ini_read_real("save","beatonce",0); //Beated game once
global.tokens = ini_read_real("save","tokens",0); //Token number
global.gameplaydone = ini_read_real("save","gameplaydone",0); //Beat whole game
//Insert variables here ^^^
ini_close();
}
Code:
//Saving Code
ini_open("save.ini");
//Insert variables here vvv
ini_write_real("save","beatonce",global.beatedonce);
ini_write_real("save","tokens",global.tokens);
ini_write_real("save","gameplaydone",global.gameplaydone);
//Insert variables here ^^^
ini_close();
Code:
//Game start event in obj_controller
scr_load(); //Load the save file
global.souls = 3; //player's lives

global.scanline = true; //scanline effect

global.sfxemit = audio_emitter_create(); //SFX emitter
global.musemit = audio_emitter_create(); //Music emitter

global.checkpoint = 0; //Checkpoints

//Checkpoints chart, 0 = nothing, 1 = lava, 2 = aqua, 3 = thunder, 4 = wood, 5 = lab

global.beatedonce = false; //Checks if beated or not to show the extras menu

global.tokens = 0; //Tokens to enter the extras

global.gameplaydone = false; //If the whole game is beated.
Right now, after i finish the game and close it then reload it. It looks like nothing happened. Would someone tell me the reason of this?

Thanks in advance.
 
Last edited:

Weird Dragon

Wizard
GMC Elder
Because you are resetting the values of the variables in the Game Start Event after you loaded the save file.

By the way why do you in the load script have en else statement that closes the ini file if you haven't opened it?
 
N

Nexusrex

Guest
I've removed that part now..So, i have to move the position of the script function, or move it to another event?
 

Weird Dragon

Wizard
GMC Elder
It can be in the same event. That would make sense. First you are initializing the variables, then if the file exists you are resetting them to the values saved in the ini file.

Edit: Well, it could make sense to load the file in a different event, because that makes it possible to restart the game with the variables set to zero.
 
Top