wait
- Last UpdatedFeb 19, 2025
- 3 minute read
The wait statement is used to interrupt the Coroutine statements execution flow loop on the wait block until the wait condition fails.
It is possible to put command statements inside the wait block with constraints.
Platform support
This element is fully supported on XR-Windows, XR-Portable Windows, XR-Portable iOS, XR-Portable Android, and XR-P 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 |
|
|
|
|
|
|
Statements
All statements supported by Command node node are allowed.
Entering and exiting wait state
Conditional waiting and restarting is the core of the Coroutine statement execution flow functionalities.
…
<wait condition="[@node.field]==value" />
…
<wait condition="[@thisCoroutine.timeFromWait]<5" />
…
<wait condition="[@%local%]!=value" >
<setlocal name="local” value="#[@%local%]*5*[@thisCoroutine.deltaTime] />
</wait>
The wait statement node allows interruption the statement execution flow and loop on the wait block.
-
As the execution flow reaches a wait statement, it stops executing if its condition is true.
-
The wait condition is evaluated at any new logic frame until it stops being true. Note that the first time the logic inside the wait block is executed is the frame after the one in which the execution flow has reached it. So, any wait checks the condition twice before executing for the first time.
-
If the wait condition is true, the code inside the wait block is executed (if present) and then the execution is halted again until the next frame.
-
If the wait condition is false, the code inside the wait is not executed and the execution flow jumps to the statement following the wait block.
-
The Coroutine timeFromWait field indicates the elapsed time since the wait block has been first executed. When the wait ends, it is reset to zero.
Types of wait conditions
The most typical wait conditions are:
-
Waiting for a time basing on Coroutine node timeFromStart or timeFromWait.
-
Waiting for an external field such as the state of something.
-
Waiting for a local value. The local value can be changed inside the wait statements; for example, incrementing it.
Code example
This is a code example for the wait statement.
…
<wait condition=”[@myCoroutine@.timeFromWait]<=5” />
….
<wait condition=”[@aNode.aField]!=aValue” >
….
</wait>
Fields
These are the fields for the wait statement.
|
Fields |
Type |
Use |
Default value |
Description |
|---|---|---|---|---|
|
condition |
sstring |
Mandatory |
Not set |
It is a wait condition. Until it is true, the Coroutine flow continues to remain halted on the wait statement (executing its block code if defined once every logic frame). |