set
- Last UpdatedAug 21, 2023
- 2 minute read
The set statement assigns an arbitrary value to any node field or local variable. It is used inside a Command node or a Coroutine node.
Important We advise you to use this statement instead of the legacy setfield and setlocal, as set works for both locals and fields. This makes the code more readable. Contrary to what setfield does, set resolves the parameters only once, which allows it to perform operations on types that might contain reserved characters, such as SJSON and others.
Platform support
This node is fully supported on XR-Windows, XR-Portable Windows, XR-Portable iOS, XR-Portable Android, and XR-Portable WASM platforms.
|
XR-WIN |
XR-P-WIN |
XR-P-IOS |
XR-P-AND |
XR-P-WASM |
|---|---|---|---|---|
|
Full support |
Full support |
Full support |
Full support |
Full support |
|
|
|
|
|
|
Code example
This is a code example for the set statement operating both on a field and a local.
<command name="showmenu">
<set name="menu.position" value="[@global.mousePosition]" />
<set name="menu.fadeIn" value="0.5" />
<local name="newLocal" type="sstring" />
<set name="newLocal" value="Menu position is: [@global.mousePosition]" />
<log text="[@newLocal]" />
</command>
Position
The set statement can be used only inside a Command node or a Coroutine node.
Fields
These are the fields for set statement.
|
Fields |
Type |
Use |
Default value |
Description |
|---|---|---|---|---|
|
condition |
sstring |
Optional |
Not set |
Applies a condition to the function execution. |
|
name |
sstring |
Mandatory |
Not set |
Defines the node field or local to be assigned. Fields use the nodeName.fieldName syntax, while locals are pointed at simply by using their name without specifying a field. |
|
value |
sstring |
Optional |
Not set |
The value to be assigned to the field. If the field is a SEVENT field, there is no need to indicate a value because the scene manager assigns a timestamp. |
|
resolve |
sbool |
Optional |
true |
Resolve the value to assign to the field before setting it or not. If set to false, the value will not be resolved and therefore always be a sstring |