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

  • disableSynchronization(): void
  • div(val: number): 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

  • 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

  • getChild(childName: string | number): Variable
  • Get the child with the specified name or at the specified index.

    If the variable is an array, prefer getChildAt. If the variable is a structure, prefer getChildNamed.

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

    Parameters

    • childName: string | number

    Returns Variable

    The child variable

  • getChildNamed(childName: string): 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

  • getChildrenCount(): number
  • getPlayerOwnership(): null | number
  • getType(): VariableType
  • getValue(): 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
  • 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
  • isStructure(): boolean
  • 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
  • pushValue(value: string | number | boolean): void
  • pushVariableCopy(variable: Variable): 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
  • 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
  • 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

  • setPlayerOwnership(playerNumber: number): 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.

  • toggle(): void
  • concatenate(str: string): void
  • getAsNumberOrString(): string | number
  • Get the value of the variable, as a number if it's one, or as a string (if it's a string or something else)

    In most cases, prefer calling getAsNumber or getAsString directly. This is a fallback in case a variable type can't be known statically for sure, like getValue.

    Returns string | number

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