Stay organized with collections
Save and categorize content based on your preferences.
blockly > Variables > renameVariable
Variables.renameVariable() function
Opens a prompt that allows the user to enter a new name for a variable. Triggers a rename if the new name is valid. Or re-prompts if there is a collision.
Signature:
export declare function renameVariable(workspace: Workspace, variable: IVariableModel<IVariableState>, opt_callback?: (p1?: string | null) => void): void;
Parameters
Parameter |
Type |
Description |
workspace |
Workspace |
The workspace on which to rename the variable. |
variable |
IVariableModel<IVariableState> |
Variable to rename. |
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. |
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 2025-05-16 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 2025-05-16 UTC."],[[["The `renameVariable` function initiates a user prompt to change a variable's name within a Blockly workspace."],["It validates the new name, triggering a rename if valid or prompting again if a name collision occurs."],["The function accepts the workspace, the variable to rename, and an optional callback function as parameters."],["This optional callback function receives the accepted new name, null if canceled, or undefined if an existing variable is selected."]]],[]]