save / load

  • Thread starter Quantum Entanglement
  • Start date
Q

Quantum Entanglement

Guest
Hi, I'm starting a new project, a sort of rpg with a huge load of variables and "things" to save/load :D
I googled everything about the save/load process in GMS and I also bought the "save custom plus encrypt" from the store, but I'm stuck.
There's anything ready to buy where you already have a menu for saving/loading many files created by the player, or a tutorial explaining how to deal with many info present in a game?
After some hours trying to figuring how to do it, I'm starting to feel lost :D ty
 
C

Christian

Guest
Use Ini files,

Here's how to save
Code:
///save_game()
//This script will save our game
if (file_exists("Save.sav")) file_delete("Save.sav");   //If the save file exists, delete it so we can overwrite it.

ini_open("Save.sav");                                   //Opens the save file for reading and writing.

//-----------------------------------------------------------------------------------------------------------------
// Information to store in our save file
//-----------------------------------------------------------------------------------------------------------------
//Use ini_write_real(sectionID,Key,informationToBeStored) for numbers
//Use ini_write_string(secionID,Key,informationToBeStored) for strings

//Example: ini_write_real("Player","Points",score) will come out as this in the save file.
//[Player]
//Points = 0

ini_write_string("Player","UserID",username);           //Writes our username.

//-----------------------------------------------------------------------------------------------------------------
ini_close();                                            //Closes our ini file for reading and writing.
And to load
Code:
///load_game()
//This script will load our game.
if (file_exists("Save.sav")) {

ini_open("Save.sav");//Opens our file for reading and writing
 
//-----------------------------------------------------------------------------------------------------------------
// Information to load from our save file
//-----------------------------------------------------------------------------------------------------------------
//Use ini_read_real(sectionID,Key,defaultValue) for numbers
//Use ini_read_string(secionID,Key,defaultValue) for strings

//Example: ini_read_real("Player","Points",0) will return this from the save file.
//[Player]
//Points = (Whatever was saved for this key).

username = ini_read_string("Player","UserID","");      //Reads our key and assigns it to our username variable.

//-----------------------------------------------------------------------------------------------------------------

ini_close();
}
This isn't a requirement but it helps me. I created scripts called "load_game" and "save_game". In most cases, I want the same information to be saved and loaded so I just call to the scripts whenever I need to instead of typing them out each time I want to save/load.

Here's an example of how saving lots of data works
Code:
///save_game()
//This script will save our game with lots of data
if (file_exists("Save.sav")) file_delete("Save.sav");   //If the save file exists, delete it so we can overwrite it.

ini_open("Save.sav");                                   //Opens the save file for reading and writing.

//-----------------------------------------------------------------------------------------------------------------
// Information to store in our save file
//-----------------------------------------------------------------------------------------------------------------
//Use ini_write_real(sectionID,Key,informationToBeStored) for numbers
//Use ini_write_string(secionID,Key,informationToBeStored) for strings

ini_write_string("Player","UserID",username);
ini_write_real("Player","Health",health);
ini_write_real("Inventory","Potions",potion_count);

/*This will come out as
[Player]
UserID = "Christian"
Health = 50

[Inventory]
Potions = 1
*/
//-----------------------------------------------------------------------------------------------------------------
ini_close();                                            //Closes our ini file for reading and writing.
 
Last edited by a moderator:
Top