Blockly is moving to the Raspberry Pi Foundation on November 10, 2025! Read the
blog
and the
FAQ.
Stay organized with collections
Save and categorize content based on your preferences.
blockly > Variables > getVariable
Variables.getVariable() function
Look up a variable on the given workspace. Always looks in the main workspace before looking in the flyout workspace. Always prefers lookup by ID to lookup by name + type.
Signature:
export declare function getVariable(workspace: Workspace, id: string | null, opt_name?: string, opt_type?: string): IVariableModel<IVariableState> | null;
Parameters
| Parameter |
Type |
Description |
| workspace |
Workspace |
The workspace to search for the variable. It may be a flyout workspace or main workspace. |
| id |
string | null |
The ID to use to look up the variable, or null. |
| opt_name |
string |
(Optional) The string to use to look up the variable. Only used if lookup by ID fails. |
| opt_type |
string |
(Optional) The type to use to look up the variable. Only used if lookup by ID fails. |
Returns:
IVariableModel<IVariableState> | null
The variable corresponding to the given ID or name + type combination, or null if not found.
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."],[],[]]