blockly > 变量 > getVariable

Variables.getVariable() 函数

在给定工作区中查找变量。始终先在主工作区中查找,然后再在弹出式工作区中查找。始终优先按 ID 查找,而不是按名称 + 类型查找。

Signature:

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

参数

参数 类型 说明
工作区 Workspace 用于搜索变量的工作区。它可以是弹出式工作区或主工作区。
id string | null 用于查找变量的 ID,或 null。
opt_name 字符串 (可选)用于查找变量的字符串。仅在按 ID 查找失败时使用。
opt_type 字符串 (可选)用于查找变量的类型。仅在按 ID 查找失败时使用。

返回

IVariableModel<IVariableState> | null

与给定 ID 或名称 + 类型组合对应的变量;如果未找到,则返回 null。