GML Saving Checkpoints

W

WolfYouTube

Guest
I was wondering how to save points right now I have

// we shouldn't save anything before loading.
if controller.loaded == false
{
exit;
}

ini_open("Save");
ini_write_real("Save","HP",obj_Player.HP);
ini_write_real("Save","CPX",obj_Player.x);
ini_write_real("Save","CPY",obj_Player.y);
ini_close();
 
J

joqlepecheur

Guest
I am not sure what your issue is since you seem to understand ini use ?
Just do the same things with a point variable ? (I'd use a global variable)
 
W

WolfYouTube

Guest
I am not sure what your issue is since you seem to understand ini use ?
Just do the same things with a point variable ? (I'd use a global variable)
When I do global.CPX & global.CPY nothing happens
 
J

joqlepecheur

Guest
ini_write only records information in a txt file.

At some point (when starting the game again) you have to use ini_read.
For exemple:
Code:
HP = 100 ;
ini_open_("Save")
HP = ini_read_real("Save", "HP",  100);
ini_close();
 

Tsa05

Member
Is your game just one room?

The way you've got it set up, your player object's Create event should have something like this:
Code:
if( file_exists("Save") ){
     ini_open("Save");
     x = ini_read_real( "CPX", x);
     y = ini_read_real("CPY", y);
     ini_close();
}
Do you see? The player object checks to see whether there's a save file, and if there is, it moves to the saved checkpoint position. If it doesn't find a checkpoint position, it goes to its current position instead.

The first time you fun the game, it won't find a save file, so nothing will happen
When you load the game, but have no checkpoint, it won't find the CPX and CPY, so it will stay still
When there is a checkpoint, it will go to the checkpoint coordinates.

But this is only going to work if the whole game is in one room! You're not storing the room information in the checkpoint. So if you have multiple rooms, be sure to also save the current_room.
 
Top