设置全局节点
概述
Set Global Node 用于在 Rivet 执行过程中设置一个全局值,该值在所有图表和子图表之间共享。这对于存储和检索需要被多个图表访问的值非常有用。
Set Global节点允许您指定全局值的ID及其值本身。ID可以是静态字符串或输入值。该值可以是任何数据类型。
- 输入
- 输出
- 编辑器设置
输入项
标题 | 数据类型 | 描述 | 默认值 | 备注 |
---|---|---|---|---|
值 | 任意 | 要设置为全局值的值。 | (必填) | 输入将被强制转换为节点设置中指定的数据类型。 |
Variable ID | string | The ID of the global value to be set. This input is only available if Use Variable ID Input is on. | (optional) | The input will be coerced into a string if it is not a string. The ID must be unique in the context. |
输出
标题 | 数据类型 | 描述 | 备注 |
---|---|---|---|
Value | Any | The value that was set as the global value. | The output will be of the same data type as the Value input. |
Previous Value | Any | The previous value of the global variable before the new value was set. | The output will be of the same data type as the Value input. If there was no previous value, this output will not be ran. |
编辑器设置
设置 | 描述 | 默认值 | 使用输入切换 | 输入数据类型 |
---|---|---|---|---|
ID | The ID of the global value to be set. | (required) | Yes | string |
Data Type | The data type of the value to be set. This determines how the Value input is coerced. | string | No | N/A |
示例1:设置一个全局值
- 创建一个文本节点并将其值设置为
Hello, World!
。 - 创建一个Set Global Node并将ID设置为
greeting
。 - 将文本节点连接到Set Global节点的
Value
输入端口。 - 运行图表。Set Global Node的
Value
输出应包含值Hello, World!
。
错误处理
如果未提供Value
输入,或者未提供全局值的ID或该ID不唯一,Set Global Node将会报错。
常见问题
问:我可以将全局值设置为数组或对象吗?
A: 是的,您可以将全局值设置为任何数据类型,包括数组和对象。您可以使用Array Node或Object Node来创建数组或对象,然后将其连接到Set Global Node的Value
输入。