modify
- Last UpdatedAug 21, 2023
- 3 minute read
The modify statement performs an operation on a node field or local variable. It is used inside a Command node or Coroutine node.
Modify can perform only operations supported by the field type that returns an output of the same type of the modified field or local.
For example, this means that modify on svec3 type fields or locals can be used to apply the scalarmul(sfloat) on the field, but not the dot(svec3). To assign arbitrary values to fields or locals, use the set statement.
Faster operations
The modify statement performs operations faster than using a setfield, setlocal, or set on the same field, so we recommend using modify, especially for onerous operations on large dictionaries (mdstring and dstring) and strings (sjson, stable, sstring).
Comparison of code using set and code using modify.
<Command name="showmenu">
<!-- slower code -->
<set name="menu.position" value="[@ menu.position.add(0 1 0)]" />
<!-- faster code -->
<modify name="menu.position" op="add" value="0 1 0" />
</Command>
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 modify statement on both fields and locals.
<Command name="showmenu">
<modify name="menu.position" op="scalarmul" value="2.5" />
<local name="position" type="svec3" value="0 1 0" />
<modify name="position" op="cross" value="1 0 0" />
<log text="0 1 0 x 1 0 0 = [@%position%]" />
</Command>
Position
The modify statement can be used only inside a Command node or Coroutine node.
Fields
These are the fields for modify 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 use name only without specifying a field. |
|
op |
SSTRING |
Mandatory |
Not set |
The method to call. See documentation of each Field data types for a complete list of supported attributes. Only attributes that return a value of the same type of the field that is being modified are supported. |
|
value |
SSTRING |
Optional |
Not set |
A comma-separated list of parameters for the operation to perform. You should put the same parameters that you would set inside the brackets of the corresponding field attribute operation in a setfield, setlocal, or set statement. For example, value="nodeName.fieldName.fieldAttribute(PARAM1,PARAM2)" becomes value="PARAM1,PARAM2". |