Planning your Savegame - coldrockgames/gml-raptor GitHub Wiki
Savegame is a very powerful tool that will take away most, if not all, of the pain that awaits you when it comes to persisting and loading your running contents. To allow Savegame to do this for you, it is necessary that you set up a plan for your data.
There are some simple but mandatory rules to follow:
- Make it a child of
Saveableor any object derived fromSaveable(see raptor's object model).
- For your Controllers, this means storing your "score", "lives", and all running values your game has in
data. - For your Levels, store their "Fields", "Chests", and all the contents in
data. - Your living objects/characters should store their "Buffs", "Equipment", and all values that describe them in
data.
- When saving, a marker is put in the savegame file on each object instance.
- This marker is part of a reference table that
Savegameuses when loading the file in order to reconnect object instances. -
BUT all those sub objects must also be
Saveableobjects and must be part of the savegame file.
- No matter how deep your
datastructure goes, it will detect other object instances in there, and it will be able to restore them on load, including their references.- Example: If your main character has a "Shield" object that surrounds him, put a reference to the shield into
data(likedata.shield = ....) - Make sure, the "shield" is also
Saveableand hasadd_to_savegameset totrue. - That's all!
Savegamewill detect this reference, store the objects, and even recreate and relink them on load!
- Example: If your main character has a "Shield" object that surrounds him, put a reference to the shield into
Savegame has no chance to restore an object link that it isn't aware of. Therefore, let me repeat this as the golden rule:
If your object holds pointers to other objects in the data member, or if it puts them into the savegame somehow, those other objects also must be Saveable and part of the savegame file or it will be impossible to restore the pointers and links when loading the game!
(In other words: Your savegame will not work if you do not follow this requirement).
- Plan your
datafor each object. - Take care, that you always keep control over the contents of
data. - Use
User Event 14andUser Event 15to store/recover your instance-specific data upon save/load. - Use the
GLOBALDATAmacro to store any global variables or structs in your savegame. - In the
Createevent of your saveable objects, use theif (!SAVEGAME_LOAD_IN_PROGRESS)macro to initialize things only, when there's not a restore currently running.
Continue reading in Savegame Versioning.