blockly > Variables > createVariableButtonHandler

Variables.createVariableButtonHandler() function

Handles "Create Variable" button in the default variables toolbox category. It will prompt the user for a variable name, including re-prompts if a name is already in use among the workspace's variables.

Custom button handlers can delegate to this function, allowing variables types and after-creation processing. More complex customization (e.g., prompting for variable type) is beyond the scope of this function.


export declare function createVariableButtonHandler(workspace: Workspace, opt_callback?: (p1?: string | null) => void, opt_type?: string): void;


Parameter Type Description
workspace Workspace The workspace on which to create the variable.
opt_callback (p1?: string | null) => void (Optional) A callback. It will be passed an acceptable new variable name, or null if change is to be aborted (cancel button), or undefined if an existing variable was chosen.
opt_type string (Optional) The type of the variable like 'int', 'string', or ''. This will default to '', which is a specific type.