Skip to main content

Home > blockly > Workspace > createVariable

Workspace.createVariable() method

Warning: This API is now obsolete.

v12: use Blockly.Workspace.getVariableMap().createVariable.

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

Signature:

createVariable(name: string, opt_type?: string | null, opt_id?: string | null): IVariableModel<IVariableState>;

Parameters

ParameterTypeDescription
namestringThe name of the variable. This must be unique across variables and procedures.
opt_typestring | null(Optional) 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_idstring | null(Optional) The unique ID of the variable. This will default to a UUID.

Returns:

IVariableModel<IVariableState>

The newly created variable.