Variable

Variable

A Variable is an object storing a value (number or a string) or children variables.

Constructor

new Variable(varDataopt)

Parameters:
Name Type Attributes Description
varData <optional>

The optional initial content of the variable.

Source:

Methods

(static) copy(source, target, merge)

Deeply copies a variable into another.

Parameters:
Name Type Description
source

The source variable.

target

The target variable.

merge

Should the target be merged with the source, or be an exact copy?

Returns:
Type Description

The target variable.

Source:

(static) isPrimitive()

Return true if the variable type is a primitive type.

Source:

add(val)

Add the given number to the variable value

Parameters:
Name Type Description
val

the number to add

Source:

addChild(childName, childVariable)

Add a child variable with the specified name.

If there is an existing child variable with this name, it is erased.

Parameters:
Name Type Description
childName

The name of the variable to add

childVariable

The variable to add as a child

Returns:
Type Description

The variable (for chaining calls)

Source:

castTo(newType)

Converts the variable into another type.

Parameters:
Name Type Description
newType

The new type of the variable

Source:

clearChildren()

Remove all the children.

Source:

clone()

Returns a deep copy of this variable.

Source:

concatenateString(str)

Concatenate the given string at the end of the variable value

Parameters:
Name Type Description
str

the string to append

Source:

div(val)

Divide the variable value by the given number

Parameters:
Name Type Description
val

the divisor

Source:

getAllChildren()

Return the object containing all the children of the variable

Returns:
Type Description

All the children of the variable

Source:

getAllChildrenArray()

Return an Array containing all the children of the variable

Source:

getAsBoolean()

Get the value of the variable, considered as a boolean

Returns:
Type Description

The boolean value of the variable.

Source:

getAsNumber()

Get the value of the variable, considered as a number

Returns:
Type Description

The number stored in the variable

Source:

getAsString()

Get the value of the variable, considered as a string

Returns:
Type Description

The string stored in the variable

Source:

getChild()

Get the child with the specified name.

If the variable has not the specified child, an empty variable with the specified name is added as child.

Returns:
Type Description

The child variable

Source:

getChildAt()

Get a variable at a given index of the array.

Source:

getChildrenCount()

Return the length of the collection

Source:

getType()

Returns the type of the variable.

Source:

getValue()

Gets the primitive value using the getter of the current type.

Source:

hasChild()

Return the child in a variable.

Check if the variable has the specified children

Returns:
Type Description

true if variable has the children with the specified name

Source:

isNumber()

Return true if the variable is a number.

Returns:
Type Description

true if the variable is a number.

Deprecated:
  • Use gdjs.Variable.getType instead.

Source:

isPrimitive()

Return true if the type of the variable is a primitive type.

Source:

isStructure()

Return true if the variable is a structure.

Returns:
Type Description

true if the variable is a structure.

Deprecated:
  • Use gdjs.Variable.getType instead.

Source:

isUndefinedInContainer()

Check if the variable must be considered as not existing in its container (usually a gdjs.VariablesContainer).

Returns:
Type Description

true if the container must consider that the variable does not exist.

Source:

mul(val)

Multiply the variable value by the given number

Parameters:
Name Type Description
val

the factor

Source:

pushValue()

Pushes a value into the array.

Source:

pushVariableCopy()

Pushes a copy of a variable into the array.

Source:

removeAtIndex()

Removes a variable at a given index of the array.

Source:

removeChild(childName)

Remove the child with the specified name.

If the variable has not the specified child, nothing is done.

Parameters:
Name Type Description
childName

The name of the child to be removed

Source:

replaceChildren(newChildren)

Replaces all the children with a new map of children.

Parameters:
Name Type Description
newChildren

The map of new children.

Source:

replaceChildrenArray(newChildren)

Replaces all the children with a new array of children.

Parameters:
Name Type Description
newChildren

The array of new children.

Source:

setBoolean(newValue)

Change the value of the variable, considered as a boolean

Parameters:
Name Type Description
newValue

The new boolean to be set.

Source:

setNumber(newValue)

Change the value of the variable, considered as a number

Parameters:
Name Type Description
newValue

The new value to be set

Source:

setString(newValue)

Change the value of the variable, considered as a string

Parameters:
Name Type Description
newValue

The new string to be set

Source:

setUndefinedInContainer()

Used (usually by gdjs.VariablesContainer) to set that the variable must be considered as not existing in the container.

Source:

setValue(newValue)

Sets the primitive value using the setter of the current type.

Parameters:
Name Type Description
newValue

The primitive value of the variable.

Source:

sub(val)

Subtract the given number to the variable value

Parameters:
Name Type Description
val

the number to subtract

Source: