Skip to content

Get

Name Mandatory Description Default Type
⬅️ Input Any input is ignored. None
Output ➡️ The output is the value read from the specified variable. 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
Default No The default value used if the variable is not set, the key is not present, or there is a type mismatch. none Any

Reads the value of the specified variable.

Details

Getis used read the value of an existing variable. All sorts of variables that can be created by Set, can be read by Get.

The :Name parameter should contain the name of the variable that's being read. If the variable is a string/numeric variable or a sequence it will be read directly. But for a table to be read its key should be passed in the parameter :Key. This will allow Get to access the particular key in the table and read it's value.

The :Default parameter specifies a value to return in case the variable being read doesn't yeild a valid value, or the sequence is malformed, or the required key is missing from the table, etc. This allows the program to continue processing even if some expected data is missing.

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 read.

Any input to this shard is ignored and its output contains the value of the variable read by Get.

Note

Get has an alias ??. This symbol represents the logical operator OR. Hence, ?? functions as an alias for Get with a default value. For example, .var1 ?? 40 means .var1 or 40 and this is effectively an alias for (Get .var1 :Default 40). 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
; create a mutable string variable and get its value
"Hello" | Set(svar) ; set value
Get(Name: svar) >= gotSvar ; get value and store it
gotSvar | Log("gotten value") ; => gotten value: Hello

; create an immutable numeric variable and get its value
100 | Ref(Name: nvar) ; set value
Get(Name: nvar) >= gotNvar ; modify numeric variable
gotNvar | Log("gotten value") ; => gotten value: 100

; create a mutable sequence and get it
[10 20 30] | Set(sequence)
Get(sequence) | Log ; => [10, 20, 30]

; create an empty sequence and try reading it with the :Default failsafe
[] | Set(seqEmpty)
Get(seqEmpty Default: "Void") | Log ; => Void

; create a table and get one of its key-values pairs
["a" "b"] | Set(table Key: "key1")
Get(table Key: "key1") | Log ; => [a, b]

; create a table and try to get a non-existent key-value using the :Default parameter
["a" "b"] | Set(table Key: "key1")
Get(table Key: "key2" Default: "Key missing") | Log ; => "Key missing"

; create mutable local/global variables and get their values
"Local" | Set(str) ; create local variable
"Global" | Set(str Global: true) ; create global variable
Get(str) | Log ; get local variable => "Local"
Get(str Global: true) | Log ; get global variable => "Global"

[info] Set - Warning: setting an already exposed variable "str", use Update to avoid this warning.
[info] [sample-wire] gotten value: Hello
[info] [sample-wire] gotten value: 100
[info] [sample-wire] [10 20 30]
[info] [sample-wire] Void
[info] [sample-wire] [a b]
[info] [sample-wire] Key missing
[info] [sample-wire] Local
[info] [sample-wire] Global