Skip to content

Update

Name Mandatory Description Default Type
⬅️ Input The value to be set to the variable. Any
Output ➡️ The input value is passed through as the output. Any
Name No The name of the variable. `` StringVar(Any)
Key No The key of the value to read from the table (parameter applicable only if the target variable is a table). none Any
Global No If the variable is available to all of the wires in the same mesh. false Bool

Modifies the value of an existing mutable variable.

Details

Update modifies the value of an existing mutable variable.

The name of the variable comes from the :Name parameter and the update value comes from the input.

Update overwrites string, numeric, and sequence variables with the new value (coming from input). However, for sequences, it cannot update a sequence at the level of elements (i.e., add elements, remove elements, change element order, etc.), so it overwrites the whole sequence with whatever you've passed in the input field.

Also, for an existing table, Update can only change the existing keys' values. It cannot add new key-value pairs to the table (do that with Set). To update existing key-values in a table you need to pass the key in the :Key parameter.

Since variables may be locally scoped (created with (:Global false); exists only for current wire) or globally scoped (created with (:Global true); exists for all wires of that mesh), both parameters :Global and :Name are used in combination to identify the correct variable to update.

The input to this shard is the update value to be applied to the mutable variables and is also passed through as this shard's output.

Note

Update has an alias >. Its an alias for Update with the defaults: (Update ...). See the code examples at the end to understand how this alias is used.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
; update a mutable string variable (by default available only to current wire)
"Hello" | Set(Name: svar)
svar | Log(".svar")                 ; => .svar: Hello
"World" | Update(svar)              ; modify string variable
svar | Log("modified .svar")        ; => .svar: World

; update a mutable numeric variable (available to all wires because Global: true)
100 | Set(Name: nvar Global: true)
nvar | Log(".nvar")                 ; => .nvar: 100
200 | Update(Name: nvar Global: true)  ; modify numeric variable
nvar | Log("modified .nvar")        ; => modified .nvar: 200

; update a mutable sequence (will overwrite it completely)
[10 20 30] | Set(Name: sequence)
[100] | Update(Name: sequence)
sequence | Log(".sequence")         ; => .sequence: [100]

; update a mutable table: update existing key-value pair
["a" "b"] | Set(Name: table1 Key: "key1")
table1 | Log(".table1")             ; => .table1: {key1: [a, b]}
["def"] | Update(table1 Key: "key1")
table1 | Log(".table1")             ; => .table1: {key1: [def]}

; Using an Update alias
; > is alias for Update(...): update an existing string variable
"Hello" | Set(Name: svarA)
svarA | Log(".svarA")               ; => .svar: Hello
"World" > svarA                     ; modify string variable
svarA | Log("modified .svar")       ; => .svar: World

; create and update local/global table variables
["a" "b"] | Set(Name: table Key: "key1")            ; create local table
["c" "d"] | Set(Name: table Key: "key1" Global: true)  ; create same-name global table
Get(table) | Log                    ; local table => {key1: [a, b]}
Get(table Global: true) | Log       ; same-name global table => {key1: [c, d]}
["X"] | Update(table Key: "key1")   ; update local table
["Y"] | Update(table Key: "key1" Global: true)  ; update same-name global table
Get(table) | Log                    ; updated local table => {key1: [X]}
Get(table Global: true) | Log       ; updated same-name global table => {key1: [Y]}

[info] [sample-wire] .svar: Hello
[info] [sample-wire] modified .svar: World
[info] [sample-wire] .nvar: 100
[info] [sample-wire] modified .nvar: 200
[info] [sample-wire] .sequence: [100]
[info] [sample-wire] .table1: {key1: [a b]}
[info] [sample-wire] .table1: {key1: [def]}
[info] [sample-wire] .svarA: Hello
[info] [sample-wire] modified .svar: World
[info] [sample-wire] {key1: [a b]}
[info] [sample-wire] {key1: [c d]}
[info] [sample-wire] {key1: [X]}
[info] [sample-wire] {key1: [Y]}