Constructor

VariableModel

new VariableModel(workspace, name, opt_type, opt_id)

Class for a variable model. Holds information for the variable including name, ID, and type.

Parameter

workspace

Blockly.Workspace

The variable's workspace.

Value must not be null.

name

string

The name of the variable. This must be unique across variables and procedures.

Value must not be null.

opt_type

Optional

string

The type of the variable like 'int' or 'string'. Does not need to be unique. Field_variable can filter variables based on their type. This will default to '' which is a specific type.

opt_id

Optional

string

The unique ID of the variable. This will default to a UUID.

See also
{Blockly.FieldVariable}

Properties

name

string

The name of the variable, typically defined by the user. It must be unique across all names used for procedures and variables. It may be changed by the user.

type

string

The type of the variable, such as 'int' or 'sound_effect'. This may be used to build a list of variables of a specific type. By default this is the empty string '', which is a specific type.

See also
{Blockly.FieldVariable}

workspace

non-null Blockly.Workspace

The workspace the variable is in.

Methods

compareByName

static

compareByName(var1, var2) returns number

A custom compare function for the VariableModel objects.

Parameter

var1

Blockly.VariableModel

First variable to compare.

var2

Blockly.VariableModel

Second variable to compare.

Returns

number -1 if name of var1 is less than name of var2, 0 if equal, and 1 if greater.

getId

getId() returns string

Returns

non-null string The ID for the variable.