Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • Variable

Index

Methods

  • add(val: number): void
  • Add the given number to the variable value

    Parameters

    • val: number

      the number to add

    Returns void

  • Add a child variable with the specified name.

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

    Parameters

    • childName: string

      The name of the variable to add

    • childVariable: Variable

      The variable to add as a child

    Returns Variable

    The variable (for chaining calls)

  • castTo(newType: VariableType): void
  • Converts the variable into another type.

    Parameters

    • newType: VariableType

      The new type of the variable

    Returns void

  • clearChildren(): void
  • Remove all the children.

    Returns void

  • Returns a deep copy of this variable.

    Returns Variable

  • concatenateString(str: string): void
  • Concatenate the given string at the end of the variable value

    Parameters

    • str: string

      the string to append

    Returns void

  • Deeply copies a variable into another.

    Parameters

    • source: Variable

      The source variable.

    • target: Variable

      The target variable.

    • Optional merge: boolean

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

    Returns Variable

    The target variable.

  • div(val: number): void
  • Divide the variable value by the given number

    Parameters

    • val: number

      the divisor

    Returns void

  • Unserialize a JSON string into this variable.

    This just logs an error if the JSON is invalid.

    Parameters

    • json: string

      A JSON string.

    Returns Variable

  • Converts a JavaScript object into a value compatible with GDevelop variables and store it inside this variable.

    Parameters

    • obj: any

      The value to convert.

    Returns Variable

  • getAllChildren(): Children
  • Return the object containing all the children of the variable.

    Returns Children

    All the children of the variable

  • Return an Array containing all the children of the variable.

    Returns Variable[]

  • getAsBoolean(): boolean
  • Get the value of the variable, considered as a boolean

    Returns boolean

    The boolean value of the variable.

  • getAsNumber(): number
  • Get the value of the variable, considered as a number

    Returns number

    The number stored in the variable

  • getAsString(): string
  • Get the value of the variable, considered as a string

    Returns 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.

    Parameters

    • childName: string

    Returns Variable

    The child variable

  • Get a variable at a given index of the array.

    Parameters

    • index: number

    Returns Variable

  • getChildrenCount(): number
  • Return the length of the collection.

    Returns number

  • getType(): VariableType
  • Returns the type of the variable.

    Returns VariableType

  • getValue(): string | number | boolean
  • Gets the primitive value using the getter of the current type.

    Returns string | number | boolean

  • hasChild(childName: string): boolean
  • Return the child in a variable.

    Check if the variable has the specified children

    Parameters

    • childName: string

    Returns boolean

    true if variable has the children with the specified name

  • isNumber(): boolean
  • Return true if the variable is a number.

    deprecated

    Use gdjs.Variable.getType instead.

    Returns boolean

    true if the variable is a number.

  • isPrimitive(type: VariableType): type is "string" | "number" | "boolean"
  • Return true if the variable type is a primitive type.

    Parameters

    • type: VariableType

    Returns type is "string" | "number" | "boolean"

  • isPrimitive(): boolean
  • Return true if the type of the variable is a primitive type.

    Returns boolean

  • isStructure(): boolean
  • Return true if the variable is a structure.

    deprecated

    Use gdjs.Variable.getType instead.

    Returns boolean

    true if the variable is a structure.

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

    Returns boolean

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

  • mul(val: number): void
  • Multiply the variable value by the given number

    Parameters

    • val: number

      the factor

    Returns void

  • pushValue(value: string | number | boolean): void
  • Pushes a value into the array.

    Parameters

    • value: string | number | boolean

    Returns void

  • pushVariableCopy(variable: Variable): void
  • Pushes a copy of a variable into the array.

    Parameters

    Returns void

  • reinitialize(varData?: Readonly<{ children?: Readonly<{ name?: string | undefined; value?: string | number | boolean | undefined; children?: Readonly<...>[] | undefined; type?: VariableType | undefined; }>[]; name?: string; type?: VariableType; value?: string | number | boolean }>): void
  • Parameters

    • Optional varData: Readonly<{ children?: Readonly<{ name?: string | undefined; value?: string | number | boolean | undefined; children?: Readonly<...>[] | undefined; type?: VariableType | undefined; }>[]; name?: string; type?: VariableType; value?: string | number | boolean }>

    Returns void

  • removeAtIndex(index: number): void
  • Removes a variable at a given index of the array.

    Parameters

    • index: number

    Returns void

  • removeChild(childName: string): void
  • Remove the child with the specified name.

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

    Parameters

    • childName: string

      The name of the child to be removed

    Returns void

  • replaceChildren(newChildren: Children): void
  • Replaces all the children with a new map of children.

    Parameters

    • newChildren: Children

      The map of new children.

    Returns void

  • replaceChildrenArray(newChildren: Variable[]): void
  • Replaces all the children with a new array of children.

    Parameters

    • newChildren: Variable[]

      The array of new children.

    Returns void

  • setBoolean(newValue: boolean): void
  • Change the value of the variable, considered as a boolean

    Parameters

    • newValue: boolean

      The new boolean to be set.

    Returns void

  • setNumber(newValue: number): void
  • Change the value of the variable, considered as a number

    Parameters

    • newValue: number

      The new value to be set

    Returns void

  • setString(newValue: string): void
  • Change the value of the variable, considered as a string

    Parameters

    • newValue: string

      The new string to be set

    Returns void

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

    Returns void

  • setValue(newValue: string | number | boolean): void
  • Sets the primitive value using the setter of the current type.

    Parameters

    • newValue: string | number | boolean

      The primitive value of the variable.

    Returns void

  • sub(val: number): void
  • Subtract the given number to the variable value

    Parameters

    • val: number

      the number to subtract

    Returns void

  • toJSObject(): any
  • Converts this variable into an equivalent JavaScript object.

    Returns any

    A JavaScript object equivalent to the variable.

  • concatenate(str: string): void
  • deprecated
    alias

    concatenateString

    Parameters

    • str: string

    Returns void

Constructors

  • new Variable(varData?: Readonly<{ children?: Readonly<{ name?: string | undefined; value?: string | number | boolean | undefined; children?: Readonly<...>[] | undefined; type?: VariableType | undefined; }>[]; name?: string; type?: VariableType; value?: string | number | boolean }>): Variable
  • Parameters

    • Optional varData: Readonly<{ children?: Readonly<{ name?: string | undefined; value?: string | number | boolean | undefined; children?: Readonly<...>[] | undefined; type?: VariableType | undefined; }>[]; name?: string; type?: VariableType; value?: string | number | boolean }>

    Returns Variable

Generated using TypeDoc