Savegame functions - Grisgram/gml-raptor Wiki

Saving & Loading (core functions)

savegame_save_game

/// @function			savegame_save_game(filename, cryptkey = "")
/// @description		Saves the entire game state to a file.
///				See docu in Saveable object for full documentation.
/// @param {string} filename	Relative path inside the working_folder where to save the file
/// @param {string=""} cryptkey	Optional. The key to use to encrypt the file.
///				If not provided, the file is written in plain text (NOT RECOMMENDED!).

savegame_load_game

/// @function			savegame_load_game(filename, cryptkey = "")
/// @description		Loads a previously saved game state (see savegame_save_game).
/// @param {string} filename	Relative path inside the working_folder where to find the file
/// @param {string=""} cryptkey	Optional. The same key that has been used to encrypt the file.
///				If not provided, the file is expected to be plain text (NOT RECOMMENDED!).
/// @returns {bool}		True, if the game loaded successfully or false, if not.

Additional structs

These functions allow you to add any additional struct data to the savegame.
This struct is in addition to the {data} node! You can store whatever you want in the savegame.

savegame_add_struct

/// @function			savegame_add_struct(name, struct)
/// @description		Adds any custom struct to the save game.
///				Can be retrieved after loading through savegame_get_struct(name).
/// @param {string} name	The name to reference this struct.
/// @param {struct} struct	The struct to save.

savegame_remove_struct

/// @function			savegame_remove_struct(name)
/// @description		Removes any custom struct from the save game.
/// @param {string} name	The name of the struct. If it does not exist, it is silently ignored.

savegame_struct_exists

/// @function			savegame_struct_exists(name)
/// @description		Checks whether a specified struct exists in the savegame.
/// @param {string} name	The name of the struct to find.
/// @returns {bool}		True, if the struct exists or false, if not.

savegame_get_struct

/// @function			savegame_get_struct(name)
/// @description		Retrieves the specified struct from the savegame.
/// @param {string} name	The name of the struct. If it does not exist, [undefined] is returned.
/// @returns {struct}		The struct or [undefined], if it does not exist.

Instance references

See Workflow and User Events for an example when to use these.

savegame_get_instance_names

/// @function			savegame_get_instance_names()
/// @description		Gets all stored instance names (= IDs) in the savegame.
/// @returns {array}		All instance names in the savegame

savegame_get_instance_of

/// @function				savegame_get_instance_of(old_instance_id)
/// @description			Retrieves the specified instance from the savegame.
/// @param {int/str} old_instance_id	The original id (when the game was saved) of the object.
/// @returns {struct}			The instance or [noone], if it does not exist.

savegame_get_instance_array_of

/// @function				savegame_get_instance_array_of(id_array)
/// @description			Maps an array of object ids to an array of instances.
///					NOTE: Only works with stored ids of savegames 
///					through savegame_get_id_array_of!
/// @param {array} id_array		An array of object ids.
/// @returns {array}			Returns an array containing the ids of the instances (in the same order).

savegame_get_id_array_of

/// @function				savegame_get_id_array_of(instance_array)
/// @description			Maps an array of object instances to an array of their id's only.
///					Useful if you want to persist linked objects in a savegame.
/// @param {array} instance_array	An array of object instances.
/// @returns {array}			Returns an array containing the instances (in the same order).
⚠️ **GitHub.com Fallback** ⚠️