Savegame functions - coldrockgames/gml-raptor GitHub Wiki
Saving & Loading (core functions)
A brief overview of all the public savegame_*
functions in one place.
[!NOTE] Reminder: All savegame functions are based on the raptor File Access (Sync/Async) base functions!
Make sure, you read this to understand the async callbacks that can be used, when calling the savegame functions.
savegame_save_game_async
/// @func savegame_save_game_async(_filename, _cryptkey = "")
/// @desc Saves the entire game state to a file.
function savegame_save_game_async(_filename, _cryptkey = "") {
[!NOTE] The
.on_finished(...)
and the.on_failed(...)
callbacks receive one argument: The_data
you might have set through.set_data(...)
in yoursavegame_save_game_async
call (see DataBuilder).
savegame_save_struct_async
/// @func savegame_save_struct_async(_filename, _cryptkey, _data)
/// @desc This function saves the game in "data-only" mode.
/// It will persist only the supplied struct, but no instances,
/// no globaldata, no room info, etc.
/// Use this to "just save a struct" which you want to be
/// restored exactly as you left it, with all the comfort of
/// constructors being called and references being restored when loaded.
function savegame_save_struct_async(_filename, _cryptkey, _data) {
[!NOTE] The
.on_finished(...)
and the.on_failed(...)
callbacks receive one argument: The_data
you might have set through.set_data(...)
in yoursavegame_save_struct_async
call (see DataBuilder).
savegame_load_game_async
/// @func savegame_load_game_async(_filename, cryptkey = "", _room_transition = undefined)
/// @desc Loads a previously saved game state (see savegame_save_game_async).
function savegame_load_game_async(_filename, cryptkey = "", _room_transition = undefined) {
[!NOTE] The
.on_finished(...)
and the.on_failed(...)
callbacks receive one argument: The_data
you might have set through.set_data(...)
in yoursavegame_load_game_async
call (see DataBuilder).
savegame_load_struct_async
/// @func savegame_load_struct_async(_filename, cryptkey)
/// @desc This is the sister-function to savegame_save_struct_async
/// The .on_finished callback will receive a "data" parameter,
/// which holds the loaded data struct.
function savegame_load_struct_async(_filename, cryptkey = "") {
[!WARNING] This function is the only exception for the
.on_finished(...)
and the.on_failed(...)
callbacks! It receives two arguments:(_loaded_data, _data)
!
The first argument is the loaded data from the file and the second argument is the_data
you might have set through.set_data(...)
in yoursavegame_load_struct_async
call (see DataBuilder).
savegame_ignore
/// @func savegame_ignore(_members...)
/// @desc Mark members of this struct class to be ignored when saved.
/// Those members will not even persist their name in the savegame.
function savegame_ignore(_members) {
A little example for this one: You may list any members of your struct class to be ignored when saving the game, like this:
function demo() : VersionedDataStruct() constructor {
construct(demo);
savegame_ignore("mem1", "mem2");
mem1 = "don't need this";
mem2 = "this neither";
name = "";
}
With this code, only the name
variable will be persisted in the savegame, mem1
and mem2
will be skipped.
savegame_exists
/// @function savegame_exists(_filename)
/// @description Checks, whether the specified savegame exists. Takes the
/// SAVEGAME_FOLDER configuration path into account
/// @returns {bool} True, if the savegame exists, or false, if not.