Planning your Savegame - Grisgram/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
Saveable
or 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
Savegame
uses when loading the file in order to reconnect object instances. -
BUT all those sub objects must also be
Saveable
objects and must be part of the savegame file.
- No matter how deep your
data
structure 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
Saveable
and hasadd_to_savegame
set totrue
. - That's all!
Savegame
will 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
data
for each object. - Take care, that you always keep control over the contents of
data
. -
Savegame
cannot recreate your objects with instance_create-structs. This new parameter from Version 2022.5 and onwards is currently not supported. When loading the game, your objects will be created without that struct parameter.
Continue reading in Savegame Versioning.