Class: VariablesContainer

VariablesContainer

new gdjs.VariablesContainer(initialVariablesData)

VariablesContainer stores variables, usually for a a RuntimeGame, a RuntimeScene or a RuntimeObject.

Name Type Description
initialVariablesData Array.<VariableData> optional

Optional array containing representations of the base variables.

Methods

add(name, variable)

Add a new variable.

Name Type Description
name string

Variable name

variable gdjs.Variable

The variable to be added

Get a variable.

Name Type Description
name string

The variable's name

Returns:
Type Description
gdjs.Variable The specified variable. If not found, an empty variable is added to the container.

Get a variable using its index. If you're unsure about how to use this method, prefer to use get. The index of a variable is its index in the data passed to initFrom.

This method is generally used by events generated code to increase lookup speed for variables.

Name Type Description
id number

The variable index

Returns:
Type Description
gdjs.Variable The specified variable. If not found, an empty variable is added to the container, but it should not happen.

has(name){boolean}

Check if a variable exists in the container.

Name Type Description
name string

The variable's name

Returns:
Type Description
boolean true if the variable exists.

initFrom(data, keepOldVariables)

Initialize variables from a container data.
If keepOldVariables is set to false (by default), all already existing variables will be erased, but the new variables will be accessible thanks to getFromIndex.
if keepOldVariables is set to true, already existing variables won't be erased and will be still accessible thanks to getFromIndex.

Name Type Description
data Array.<VariableData>

The array containing data used to initialize variables.

keepOldVariables Boolean optional

If set to true, already existing variables won't be erased.

Remove a variable. (the variable is not really removed from the container to avoid creating garbage, but marked as undefined)

Name Type Description
name string

Variable to be removed