Skip to main content

Home > blockly > Variables > getOrCreateVariablePackage

Variables.getOrCreateVariablePackage() function

Helper function to look up or create a variable on the given workspace. If no variable exists, creates and returns it.

Signature:

export declare function getOrCreateVariablePackage(workspace: Workspace, id: string | null, opt_name?: string, opt_type?: string): IVariableModel<IVariableState>;

Parameters

ParameterTypeDescription
workspaceWorkspaceThe workspace to search for the variable. It may be a flyout workspace or main workspace.
idstring | nullThe ID to use to look up or create the variable, or null.
opt_namestring(Optional) The string to use to look up or create the variable.
opt_typestring(Optional) The type to use to look up or create the variable.

Returns:

IVariableModel<IVariableState>

The variable corresponding to the given ID or name + type combination.