Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ XR Studio

Coroutine node

  • Last UpdatedFeb 19, 2025
  • 3 minute read

A Coroutine node extends the functionalities of Command node by supporting functionalities to:

  • Span the execution flow on multiple logic frames using the wait statement to exit from a frame and reenter in the next frame.

  • Better organize execution flow using goto and label statements.

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

Full support

Full support

Full support

Full support

Full support

Passing data and returning values

Because the Coroutine is an extension of the Command node, it provides the same functionalities to pass typed or not typed data and to return a typed value.

Notes

  • Invoking a coroutine that is still running, causes it to restart. This should be taken in account when passing data to it.

  • Also, since a coroutine can span multiple frames, its completion state should be checked before reading its returnValue to avoid getting the previous execution result.

Coroutine and time

A Coroutine can span multiple logic frames; therefore, it needs to have access to time-related values.

  • The timeFromStart field returns the time since Coroutine execution start.

  • The timeFromWait field returns time from the last entered wait block. This can be used to wait for a specific interval.

  • The deltaTime field returns the time since the last logic frame execution.

Code example

This is a code example for the Coroutine node.

<Coroutine name="myCoroutine" >

<local name="myLocal" type="sint" value="0" />

<log text="starting coroutine" />

<label name="myLabel" />

<wait condition="[@myCoroutine.timeFromWait]&lt;5">

<log text="elapsed [@myCoroutine.deltaTime]" />

</wait>

<log text="Waited for 5 seconds" />

<setlocal name="myLocal" value="#[@%myLocal%]+1#" />

<goto label="myLabel" condition="[@%myLocal%]!=5" />

</Coroutine>

Coroutine fields

These are the fields for the Coroutine node.

Only the node-specific fields are indicated, not those inherited from Command node.

Fields

Type

Use

Default value

Description

deltaTime

sfloat

Read Only

Internally Calculated

The time elapsed since previous logic frame execution.

state

senum

Read Only

Internally Calculated

When the Coroutine is executing, the state changes to running, then changes back to stopped when the execution ends. This field can be used to avoid executing again a Coroutine that has not yet completed.

timeFromStart

sfloat

Read Only

Internally Calculated

The time since the Coroutine execution start.

timeFromWait

sfloat

Read Only

Internally Calculated

The time since the last entered wait block (if still inside the wait block). Otherwise it is set to zero.

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in