GMS 2 How Do I Make a Simple Save System

Tobey

Member
I've followed multiple tutorials(
) to try and make one but none of them worked for me. I need a save system that saves the x, y position of the player, the current room and a bunch of other variables that check if certain cut scenes have occurred (eg. intro_scene_occurred). It also needs to be loaded on game start up.
 

chamaeleon

Member
I've followed multiple tutorials(
) to try and make one but none of them worked for me. I need a save system that saves the x, y position of the player, the current room and a bunch of other variables that check if certain cut scenes have occurred (eg. intro_scene_occurred). It also needs to be loaded on game start up.
Maybe you can start by explaining why using ini files as the simplest way to get started is not working for you. Ideally with some code to go along with it.
 
I use ini files. They are very effective and easy to use. You can save save games and also game settings or any other variable value. It basically works like this:

Save:
- open file.ini
- write file
- close file

Load:
- open file.ini
- Read file
- close file

Very simple. Room active for example:

GML:
var vroom = room;
// Save current room
ini_open( file.ini );
ini_write_real( "STATE", "current_room", vroom );
close_ini();
Load:

GML:
var vroom;
ini_open( file.ini );
vroom = ini_read_real( "STATE", "current_room", room_first );
close_ini();

room_goto( vroom );
 
Last edited:

Tobey

Member
GML:
var vroom = room;
// Save current room
ini_open( file.ini );
ini_write_real( "STATE", "current_room", vroom );
close_ini();
Load:

GML:
var vroom;
ini_open( file.ini );
vroom = ini_read_real( "STATE", "current_room", room_first );
close_ini();

room_goto( vroom );
Is it possible to save and load an array using this eg. save = [x, y, room, "test", event1, etc.]

Or possibly a less tedious way to save as I have ALOT of variables.
 

samspade

Member
Is it possible to save and load an array using this eg. save = [x, y, room, "test", event1, etc.]

Or possibly a less tedious way to save as I have ALOT of variables.
No. Not built in at least. You could code something so that the final result would look something like that, but you would have to do that yourself.

If you used the json structure then you could get pretty close. As you could just put all those variables into a list, add it to a map, and then save the map (and do so for as many objects as you want).
 

Tobey

Member
No. Not built in at least. You could code something so that the final result would look something like that, but you would have to do that yourself.

If you used the json structure then you could get pretty close. As you could just put all those variables into a list, add it to a map, and then save the map (and do so for as many objects as you want).
Ok, I'm just gonna use the .ini files (I already tried .json, which I couldnt get to work).

Thanks for the help everyone.
 
Top