blockly > 变量 > getOrCreateVariablePackage

Variables.getOrCreateVariablePackage() 函数

用于在给定工作区中查找或创建变量的辅助函数。如果不存在变量,则创建并返回它。

Signature:

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

参数

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

返回

IVariableModel<IVariableState>

与给定 ID 或名称 + 类型组合对应的变量。