Stay organized with collections
Save and categorize content based on your preferences.
blockly > Variables > createVariableButtonHandler
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.
Signature:
export declare function createVariableButtonHandler(workspace: Workspace, opt_callback?: (p1?: string | null) => void, opt_type?: string): void;
Parameters
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. |
Returns:
void
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-18 UTC."],[[["`createVariableButtonHandler` facilitates the creation of new variables within a Blockly workspace, managing user prompts for variable names and handling potential naming conflicts."],["This function can be used by custom button handlers, offering flexibility for defining variable types and incorporating post-creation actions."],["While offering basic variable creation functionality, `createVariableButtonHandler` is not designed for complex customizations like prompting for variable type."],["The function takes the workspace, an optional callback for processing the new variable name, and an optional variable type as parameters."]]],[]]