Skip to content
Lemonymous edited this page Apr 15, 2022 · 1 revision

Table of Contents

 

PersonalSavedata

A module providing functions intended to make code related to storing and retrieving save data less verbose when nesting many tables in game and mission save data.

The difference between game and mission save data is that game save data persists as long as you are in a game, while mission save data only persists for the current mission.

A global variable of the same name (PersonalSavedata) will also be created, keeping track of versioning of this module.

 

GAME_savedata

This function takes any amount of arguments. Each argument must be a string, and will determine in which location the returned object will save your data. (see: Examples)

Returns an magic table object, which when altered during a game, will update the corresponding save data. When altering the object while not in a game, you alter its default state. This is the fallback state used when trying to do arithmetic on save data that might not be initialized in the current game's save data.

Examples:

	-- Create an object with the target GAME.Kern.Achievements
	-- When altering game_savedata, the corresponding location
	-- in GAME.Kern.Achievements will be altered as well, and
	-- then stored in the actual save game. To avoid mod
	-- conflicts it is adviced to use unique names, at least
	-- for the first argument.
	local game_savedata = GAME_savedata("Kern", "Achievements")

	-- Set a default fallback value for a variable.
	-- When altering game_savedata outside of a game, we don't
	-- actually write any save data. Instead we define what what
	-- we want game_savedata.kills to return while in a game,
	-- if GAME.Kern.Achievements.kills is nil.
	game_savedata.kills = 0

	-- If we then have a function that is called while in a game,
	-- we can do the following with no fear of any of GAME.Kern,
	-- GAME.Kern.Achievements, or GAME.Kern.Achievements.kills to
	-- be nil. game_savedata will simply handle all of that
	-- internally.
	local function onPawnKilled(mission, pawn)
		game_savedata.kills = game_savedata.kills + 1
	end

	-- In addition, every time a new game is started, there will be
	-- a new GAME object created, so the default fallback
	-- game_savedata.kills that we set once at init, will still be
	-- there as a fallback in this new game. There is no need to
	-- initialize it again, or to reset it.
	-- The following will result in an error. It is not allowed to
	-- store tables in game_savedata.
	game_savedata.someTable = {}

	-- If you need to store a table, you can create additional objects.
	local game_savedata_someTable = Game_savedata("Kern", "Achievements", "NestedTable")

 

Mission_savedata

This function is very similar to GAME_savedata. The usage is exactly the same; with the exception that this saves to the current mission object instead of GAME. This means that anything saved to objects created by Mission_savedata will only persist for the duration of the mission.

 

Clone this wiki locally