createshare
- Last UpdatedJan 18, 2024
- 3 minute read
The createshare is a statement that can be used inside Command or Coroutine to share a field value to the messagebus at runtime. The share is instantly created, so the instance starts to send and receive values right away. For further information on shares, see share.
Platform support
This node is fully supported on XR-Windows, XR-Portable Windows, XR-Portable iOS, XR-Portable Android, and XR-Portable Hololens 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 |
|
|
|
|
|
|
Runtime application synchronization
It's important to notice that in order to effectively share a field value among runtime instances, all of them must have the share. Creating a share on an instance while not creating it on other instances would result in not sharing the field value with any other instance.
Keep this in mind when using createshare and when creating scripts that call for the same field. It is good to determine which runtime instances are the writers of the field and which are the readers.
Code example
This is a code example for the createshare statement.
<Command name="createLocalInstance" args="playerName=sstring" >
<createnode name="[@%playerName%]_box" nodeType="Rect2D" visible="true" size="240 48" position="[R200 #48*[@localInstances.value.length]#]" order="50" />
<createnode name="[@%playerName%]_text" nodeType="Text2D" parent="[R[@%playerName%]_box]" color="0 0 0" visible="true" size="240 48" text="[R[@%playerName%]]" order="49" />
<createshare field="[@%playerName%]_text.text" direction="[?[@%playerName%]==[@instanceName.value],out,in]" statezero="true" />
<createshare field="[@%playerName%]_box.position" direction="[?@def:Message.type@==server,out,in]" statezero="true" />
<modify name="localInstances.value" op="add" value="[@%playerName%]" />
</Command>
Fields
These are the fields for createshare statement.
|
Fields |
Type |
Use |
Default value |
Description |
|---|---|---|---|---|
|
field |
sstring |
Mandatory |
Not set |
The name of the field to share in the form of node.field. |
|
direction |
sstring |
Optional |
inout |
Specifies the share direction: in, out, or inout. |
|
statezero |
sbool |
Optional |
true |
Set to false to skip zero state coming from the server. |
|
refreshTime |
sdouble |
Optional |
-1 |
If greater than zero, this value will be used as the minimum time elapsed between the sharing of a field value. For example, a field that changes every game frame with a refreshTime of 0.5 seconds will be exchanged only twice every second. Note that refreshTime and tolerance are mutually exclusive. In cases where both are defined, refreshTime will be used and tolerance will be ignored. |
|
tolerance |
sdouble |
Optional |
-1 |
If greater than zero, this value will be used as the minimum variation for which the shared field is sent to other instances. Only fields of type sint, sfloat, sdouble, svec2, svec3, svec4 and squat can use this field. Keep in mind that svec2, svec3, svec4 and squat do a mere comparison of corresponding values, and not a real distance check. For example, on svec2 the tolerance check is passed if x or y value are different more than tolerance from the latest sent values: Abs(x -x1) >= tolerance || Abs(y-y1) >= tolerance. Also note that refreshTime and tolerance are mutually exclusive. In cases where both are defined, refreshTime will be used and tolerance will be ignored. |