Skip to main content

Variables & Persistent Storage

These functions can be used to store data and keep it around between scenes. The key/value pairs are saved with the player's savegame. Because all Scenes each have their own self-contained script environment, this is the one and only way to communicate data between two Scenes, or to remember data the next time the same Scene is visited.

Keys must be unique (as they identify the thing you want to save or load), but are not case-sensitive (e.g. 'MyNumber' and 'mYnUmBeR' are the same).

Storage.GetFlag
name
  • name (string) - the unique name of the value to retrieve
  • (boolean) - the state of the requested flag
Returns the state of a flag (boolean). The default value is false for flags that were never set before.
Storage.GetNumber
name
  • name (string) - the unique name of the value to retrieve
  • (number) - the requested value
Returns a number from storage. The default value is 0 for numbers that were never set before.
Storage.GetString
name
  • name (string) - the unique name of the value to retrieve
  • (string) - the requested value
Returns a string from storage. The default value is an empty string (not nil!) if never set before.
Storage.SetFlag
name
value
  • name (string) - the unique name of the value to store
  • value (boolean) - the new value to associate with this name
Saves a flag with the specified key to persistent storage.
Storage.SetNumber
name
value
  • name (string) - the unique name of the value to store
  • value (number) - the new value to associate with this name
Saves a number with the specified key to persistent storage.
Storage.ModifyNumber
name
delta
  • name (string) - the unique name of the value to store
  • delta (number) - the change, positive or negative, to add to the current value
Adds a value to a number with the specified key. This is functionally equivalent to chaining Storage.GetNumber and Storage.SetNumber together, but a bit more concise.
Storage.SetString
name
value
  • name (string) - the unique name of the value to store
  • value (string) - the new value to associate with this name
Saves a string with the specified key to persistent storage.