API Docs for:
Show:

VariableStore Class

Module: gs

A storage for different kind of game variables. The following scopes for variables exist:

  • Local Variables -> Only valid for the current scene.
  • Global Variables -> Valid for the whole game but bound to a single save-game.
  • Persistent Variables -> Valid for the whole game indepentent from the save-games.

The following data-types exist:

- Strings -> Variables storing text data. - Numbers -> Variables storing integer number values. - Booleans -> Variables storing boolean values. (Called "Switches" for easier understanding) - Lists -> Variables storing multiple other variables. Lists can also contain Lists.

Local variables are stored by scene UID. For each scene UID a list of local variables is stored.

Global and persistent variables are stored and a specific domain. A domain is just a unique name such as com.example.game for example. The default domain is an empty string. Domains are useful to avoid overlapping of variable numbers when sharing content with other users.

Methods

booleanValueAtIndex

(
  • scope
  • index
)
Boolean

Gets the value of a boolean variable at the specified index.

Parameters:

  • scope Number
    • The variable scope.
  • index Number
    • The variable's index.

Returns:

Boolean:

The boolean value of the variable.

booleanValueOf

(
  • object
)
Object

Gets the value of a specified boolean variable.

Parameters:

  • object Object
    • The variable to get the value from.

Returns:

Object:

The boolean value of the variable.

changeDomain

(
  • domain
)

Changes the current domain.

Parameters:

  • domain String
    • The domain to change to.

clearAllLocalVariables

()

Clears all local variables for all contexts/scenes/common-events.

clearGlobalVariables

(
  • type
  • range
)

Clears global variables.

Parameters:

  • type Number
    • Determines what kind of variables should be cleared.
    • 0 = All
    • 1 = Switches / Booleans
    • 2 = Numbers
    • 3 = Texts
    • 4 = Lists
  • range Object
    • The variable id-range to clear. If null all variables are cleared.

clearGlobalVariables

()

Clears all global variables

clearLocalVariables

(
  • context
  • type
  • range
)

Clears all local variables for a specified context. If the context is not specified, all local variables for all contexts/scenes/common-events are cleared.

Parameters:

  • context Object
    • The context to clear the local variables for. If null, all
  • type Number
    • Determines what kind of variables should be cleared.
    • 0 = All
    • 1 = Switches / Booleans
    • 2 = Numbers
    • 3 = Texts
    • 4 = Lists
  • range Object
    • The variable id-range to clear. If null all variables are cleared.

clearPersistentVariables

(
  • type
  • range
)

Clears persistent variables.

Parameters:

  • type Number
    • Determines what kind of variables should be cleared.
    • 0 = All
    • 1 = Switches / Booleans
    • 2 = Numbers
    • 3 = Texts
    • 4 = Lists
  • range Object
    • The variable id-range to clear. If null all variables are cleared.

clearVariables

(
  • numbers
  • strings
  • booleans
  • lists
  • type
  • range
)

Clears specified variables.

Parameters:

  • numbers Number
    • The number variables to clear.
  • strings String
    • The string variables to clear.
  • booleans Boolean
    • The boolean variables to clear.
  • lists Array
    • The list variables to clear.
  • type Number
    • Determines what kind of variables should be cleared.
    • 0 = All
    • 1 = Switches / Booleans
    • 2 = Numbers
    • 3 = Texts
    • 4 = Lists
  • range Object
    • The variable id-range to clear. If null all specified variables are cleared.

listObjectOf

(
  • object
)
Object

Gets the value of a specified list variable.

Parameters:

  • object Object
    • The list-variable/object to get the value from.

Returns:

Object:

The list-object.

numberValueAtIndex

(
  • scope
  • index
)
Object

Gets the value of a number variable at the specified index.

Parameters:

  • scope Number
    • The variable scope.
  • index Number
    • The variable's index.

Returns:

Object:

The number value of the variable.

numberValueOf

(
  • object
)
Object

Gets the value of a specified number variable.

Parameters:

  • object Object
    • The variable to get the value from.

Returns:

Object:

The number value of the variable.

onDataBundleRestore.

(
  • Object
  • gs.ObjectCodecContext
)

Called if this object instance is restored from a data-bundle. It can be used re-assign event-handler, anonymous functions, etc.

Parameters:

  • Object Object

    data - The data-bundle

  • gs.ObjectCodecContext Object

    context - The codec-context.

setBooleanValueAtIndex

(
  • scope
  • index
  • value
)

Sets the value of the boolean variable at the specified index.

Parameters:

  • scope Number
    • The variable scope.
  • index Number
    • The variable's index.
  • value Boolean
    • The value to set.

setBooleanValueTo

(
  • variable
  • value
)

Sets the value of a specified boolean variable.

Parameters:

  • variable Object
    • The variable to set.
  • value Boolean
    • The value to set.

setListObjectTo

(
  • variable
  • value
)

Sets the value of a specified list variable.

Parameters:

  • variable Object
    • The variable to set.
  • value Object
    • The value to set.

setNumberValueAtIndex

(
  • scope
  • index
  • value
)

Sets the value of the number variable at the specified index.

Parameters:

  • scope Number
    • The variable scope.
  • index Number
    • The variable's index.
  • value Number
    • The value to set.

setNumberValueAtIndex

(
  • variable
  • value
)

Sets the value of a specified number variable.

Parameters:

  • variable Number
    • The variable to set.
  • value Number
    • The value to set.

setStringValueAtIndex

(
  • scope
  • index
  • value
)

Sets the value of the string variable at the specified index.

Parameters:

  • scope Number
    • The variable scope.
  • index Number
    • The variable's index.
  • value String
    • The value to set.

setStringValueTo

(
  • variable
  • value
)

Sets the value of a specified string variable.

Parameters:

  • variable Object
    • The variable to set.
  • value String
    • The value to set.

setup

(
  • context
)

Initializes the variables. Should be called whenever the context changes. (Like after a scene change)

Parameters:

  • context Object
    • The context(current scene) needed for local variables. Needs have at least an id-property.

setupLocalVariables

(
  • context
)

Initializes the local variables for the specified context. Should be called on first time use.

Parameters:

  • context Object
    • The context(current scene). Needs have at least an id-property.

setupTempVariables

(
  • context
)

Initializes the current temp variables for the specified context. Should be called whenever the context changed.

Parameters:

  • context Object
    • The context(current scene). Needs have at least an id-property.

setupVariables

(
  • context
  • property
  • defaultValue
)

Initializes the specified kind of variables.

Parameters:

  • context Object
    • The context(current scene). Needs have at least an id-property.
  • property String
    • The kind of variables (property-name).
  • defaultValue Object
    • The default value for each variable.

stringValueAtIndex

(
  • scope
  • index
)
String

Gets the value of a string variable at the specified index.

Parameters:

  • scope Number
    • The variable scope.
  • index Number
    • The variable's index.

Returns:

String:

The string value of the variable.

stringValueOf

(
  • object
)
String

Gets the value of a specified string variable.

Parameters:

  • object Object
    • The variable to get the value from.

Returns:

String:

The string value of the variable.

Properties

booleans

Boolean

The global boolean variables of the current domain.

context

Object

Current local variable context

domain

Object

Current domain for global and persistent variables. Each domain has its own variables. Please use changeDomain method to change the domain.

domains

String

List of available domains for global and persistent variables.

globalVariablesByDomain

Object[]

The storage of all global variables by domain.

lists

Object[]

The global list variables of the current domain.

localBooleans

Number

localBooleans

Object

The local boolean variables.

localLists

Object[]

localLists

Object

The local list variables.

localNumbers

Object

The local number variables.

localStrings

Object

The local string variables.

numbers

Number

The global number variables of the current domain.

persistentBooleans

Boolean

The persistent boolean variables of the current domain.

persistentLists

Object[]

The persistent list variables of the current domain.

persistentNumbers

Number

The persistent number variables of the current domain.

persistentStrings

String

The persistent string variables of the current domain.

persistentVariablesByDomain

Object[]

The storage of all persistent variables by domain.

strings

String

The global string variables of the current domain.

tempNumbers

Number

tempStrings

String