blockly > Workspace > createVariable
Workspace.createVariable() 方法
v12:使用 Blockly.Workspace.getVariableMap().createVariable。
创建具有指定名称、可选类型和可选 ID 的变量。
Signature:
createVariable(name: string, opt_type?: string | null, opt_id?: string | null): IVariableModel<IVariableState>;
参数
| 参数 | 类型 | 说明 |
|---|---|---|
| name | 字符串 | 变量的名称。此名称在变量和过程之间必须是唯一的。 |
| opt_type | string | null | (可选)变量的类型,例如“int”或“string”。无需具有唯一性。Field_variable 可以根据变量类型进行过滤。这将默认为“'”,这是一种特定类型。 |
| opt_id | string | null | (可选)变量的唯一 ID。此值将默认为 UUID。 |
返回:
IVariableModel<IVariableState>
新创建的变量。