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:

Does the object need to be saved/restored?

Always keep in mind that everything you put into data will be part of the savegame file

  • 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.

This even includes other object instances

  • 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.

Savegame can handle object links for you.

  • 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 (like data.shield = ....)
    • Make sure, the "shield" is also Saveable and has add_to_savegame set to true.
    • That's all! Savegame will detect this reference, store the objects, and even recreate and relink them on load!

The golden rule

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).


Final words

  • 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.

⚠️ **GitHub.com Fallback** ⚠️