Constructor

VariableMap

new VariableMap(workspace)

Class for a variable map. This contains a dictionary data structure with variable types as keys and lists of variables as values. The list of variables are the type indicated by the key.

Parameter

workspace

Blockly.Workspace

The workspace this map belongs to.

Value must not be null.

Property

workspace

non-null Blockly.Workspace

The workspace this map belongs to.

Methods

clear

clear()

Clear the variable map.

createVariable

createVariable(name, opt_type, opt_id) returns Blockly.VariableModel

Create a variable with a given name, optional type, and optional ID.

Parameter

name

string

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

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.

Returns

Blockly.VariableModel The newly created variable.

deleteVariable

deleteVariable(variable)

Delete a variable.

Parameter

variable

Blockly.VariableModel

Variable to delete.

Value must not be null.

deleteVariableById

deleteVariableById(id)

Delete a variables by the passed in ID and all of its uses from this workspace. May prompt the user for confirmation.

Parameter

id

string

ID of variable to delete.

getAllVariables

getAllVariables() returns Array of non-null Blockly.VariableModel

Return all variables of all types.

Returns

non-null Array of non-null Blockly.VariableModel List of variable models.

getVariable

getVariable(name, opt_type) returns Blockly.VariableModel

Find the variable by the given name and type and return it. Return null if it is not found.

Parameter

name

string

The name to check for.

opt_type

Optional

string

The type of the variable. If not provided it defaults to the empty string, which is a specific type.

Returns

Blockly.VariableModel The variable with the given name, or null if it was not found.

getVariableById

getVariableById(id) returns Blockly.VariableModel

Find the variable by the given ID and return it. Return null if it is not found.

Parameter

id

string

The ID to check for.

Returns

Blockly.VariableModel The variable with the given ID.

getVariablesOfType

getVariablesOfType(type) returns Array of non-null Blockly.VariableModel

Get a list containing all of the variables of a specified type. If type is null, return list of variables with empty string type.

Parameter

type

string

Type of the variables to find.

Value may be null.

Returns

non-null Array of non-null Blockly.VariableModel The sought after variables of the passed in type. An empty array if none are found.

getVariableTypes

getVariableTypes() returns Array of string

Return all variable types. This list always contains the empty string.

Returns

non-null Array of string List of variable types.

getVariableUsesById

getVariableUsesById(id) returns Array of non-null Blockly.Block

Find all the uses of a named variable.

Parameter

id

string

ID of the variable to find.

Returns

non-null Array of non-null Blockly.Block Array of block usages.

renameVariable

renameVariable(variable, newName)

Rename the given variable by updating its name in the variable map.

Parameter

variable

Blockly.VariableModel

Variable to rename.

Value must not be null.

newName

string

New variable name.

renameVariableById

renameVariableById(id, newName)

Rename a variable by updating its name in the variable map. Identify the variable to rename with the given ID.

Parameter

id

string

ID of the variable to rename.

newName

string

New variable name.