Class: Variable

Variable

new gdjs.Variable(varData)

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

Name Type Description
varData VariableData optional

The optional initial content of the variable.

Members

innerchildDataVariableData

Methods

add(val)

Add the given number to the variable value

Name Type Description
val number

the number to add

clearChildren()

Remove all the children.

If the variable is not a structure, nothing is done.

concatenate(str)

Concatenate the given string at the end of the variable value

Name Type Description
str string

the string to append

div(val)

Divide the variable value by the given number

Name Type Description
val number

the divisor

getAllChildren(){Object.<string, gdjs.Variable>}

Return the object containing all the children of the variable

Returns:
Type Description
Object.<string, gdjs.Variable> All the children of the variable

getAsNumber(){number}

Get the value of the variable, considered as a number

Returns:
Type Description
number The number stored in the variable

getAsString(){string}

Get the value of the variable, considered as a string

Returns:
Type Description
string The string stored in the variable

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
gdjs.Variable The child variable

hasChild(){boolean}

Return the child in a variable.

Check if the variable has the specified children

Returns:
Type Description
boolean true if variable has the children with the specified name

isNumber(){boolean}

Return true if the variable is a number.

Returns:
Type Description
boolean true if the variable is a number.

isStructure(){boolean}

Return true if the variable is a structure.

Returns:
Type Description
boolean true if the variable is a structure.

mul(val)

Multiply the variable value by the given number

Name Type Description
val number

the factor

removeChild(childName)

Remove the child with the specified name.

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

Name Type Description
childName string

The name of the child to be removed

setNumber(newValue)

Change the value of the variable, considered as a number

Name Type Description
newValue number

The new value to be set

setString(newValue)

Change the value of the variable, considered as a string

Name Type Description
newValue string

The new string to be set

sub(val)

Subtract the given number to the variable value

Name Type Description
val number

the number to subtract