Dynamic Variables: Difference between revisions

From Resonite Wiki
make page translatable
Marked this version for translation
Line 3: Line 3:
{{stub}}
{{stub}}


== <translate>Overview</translate> ==
== <translate><!--T:1--> Overview</translate> ==


<translate>'''Dynamic variables''' allow you to read and write data by name. This makes it easy to manage data in large systems; every bit of data is clearly labeled, and you can break data into multiple '''spaces''' to keep your systems separate.</translate>
<translate><!--T:2--> '''Dynamic variables''' allow you to read and write data by name. This makes it easy to manage data in large systems; every bit of data is clearly labeled, and you can break data into multiple '''spaces''' to keep your systems separate.</translate>


== <translate>Naming Restrictions</translate> ==
== <translate><!--T:3--> Naming Restrictions</translate> ==
<translate>When using Dynamic Variables there are some restrictions and limitations on naming both spaces and variables within those spaces.</translate>
<translate><!--T:4--> When using Dynamic Variables there are some restrictions and limitations on naming both spaces and variables within those spaces.</translate>


<translate>Space and Variable Names '''cannot contain''':</translate>
<translate><!--T:5--> Space and Variable Names '''cannot contain''':</translate>
* <translate>Any symbols</translate>  
* <translate><!--T:6--> Any symbols</translate>  
** <translate>As defined in C# [https://docs.microsoft.com/en-us/dotnet/api/system.char.issymbol?view=net-5.0 Char.IsSymbol]</translate>
** <translate><!--T:7--> As defined in C# [https://docs.microsoft.com/en-us/dotnet/api/system.char.issymbol?view=net-5.0 Char.IsSymbol]</translate>
* <translate>Any Punctuation / Whitespace</translate>
* <translate><!--T:8--> Any Punctuation / Whitespace</translate>
** <translate>As defined in C# [https://docs.microsoft.com/en-us/dotnet/api/system.char.ispunctuation?view=net-5.0 Char.IsPunctuation] and C# [https://docs.microsoft.com/en-us/dotnet/api/system.char.iswhitespace?view=net-5.0 Char.IsWhiteSpace]</translate>
** <translate><!--T:9--> As defined in C# [https://docs.microsoft.com/en-us/dotnet/api/system.char.ispunctuation?view=net-5.0 Char.IsPunctuation] and C# [https://docs.microsoft.com/en-us/dotnet/api/system.char.iswhitespace?view=net-5.0 Char.IsWhiteSpace]</translate>
* <translate>'''Except''' for period (.), underscore (_) and space ( ).</translate>
* <translate><!--T:10--> '''Except''' for period (.), underscore (_) and space ( ).</translate>


== <translate>Usage</translate> ==
== <translate><!--T:11--> Usage</translate> ==


<translate>Optionally, the name can be prefixed by the name of a '''space''', terminated by a /, to choose a specific variable space to use. This is useful to distinguish between unrelated systems that all use dynamic variables.</translate>
<translate><!--T:12--> Optionally, the name can be prefixed by the name of a '''space''', terminated by a /, to choose a specific variable space to use. This is useful to distinguish between unrelated systems that all use dynamic variables.</translate>


<translate>Some valid names include:</translate>
<translate><!--T:13--> Some valid names include:</translate>


* <translate>Health -- no space defined, named Health</translate>
* <translate><!--T:14--> Health -- no space defined, named Health</translate>
* <translate>World/Color -- named Color, in the World space</translate>
* <translate><!--T:15--> World/Color -- named Color, in the World space</translate>
* <translate>MyCoolSystem/Score -- named Score, in the MyCoolSystem space</translate>
* <translate><!--T:16--> MyCoolSystem/Score -- named Score, in the MyCoolSystem space</translate>


=== <translate>Spaces</translate> ===
=== <translate><!--T:17--> Spaces</translate> ===


<translate>Dynamic variables can live anywhere in or under the slot containing a [[DynamicVariableSpace (Component)|DynamicVariableSpace]] component.</translate>
<translate><!--T:18--> Dynamic variables can live anywhere in or under the slot containing a [[DynamicVariableSpace (Component)|DynamicVariableSpace]] component.</translate>


<translate>So, a variable space on the world root can be used from anywhere, whilst a variable space on your avatar can be used from anything stored in your avatar.</translate>
<translate><!--T:19--> So, a variable space on the world root can be used from anywhere, whilst a variable space on your avatar can be used from anything stored in your avatar.</translate>


=== <translate>Variables</translate> ===
=== <translate><!--T:20--> Variables</translate> ===


<translate>The simplest way to use dynamic variables is to use the [[DynamicValueVariable%601_(Component)|DynamicValueVariable<T>]] and [[DynamicReferenceVariable%601_(Component)|DynamicReferenceVariable<T>]] components. These are for value (int, float, String, etc.) and reference (Slot, User, etc.) types, respectively.</translate>
<translate><!--T:21--> The simplest way to use dynamic variables is to use the [[DynamicValueVariable%601_(Component)|DynamicValueVariable<T>]] and [[DynamicReferenceVariable%601_(Component)|DynamicReferenceVariable<T>]] components. These are for value (int, float, String, etc.) and reference (Slot, User, etc.) types, respectively.</translate>
   
   
<translate>These components store a value or reference directly. If two variable components have the same name, then they will have identical contents.</translate>
<translate><!--T:22--> These components store a value or reference directly. If two variable components have the same name, then they will have identical contents.</translate>


=== <translate>Fields</translate> ===
=== <translate><!--T:23--> Fields</translate> ===


<translate>If you want to use an existing field or reference as the contents of a dynamic variable, you can use the [[DynamicField%601_(Component)|DynamicField<T>]] or [[DynamicReference%601_(Component)|DynamicReference<T>]] components. Instead of storing something directly, they point at a field that contains a value or reference type, respectively.</translate>
<translate><!--T:24--> If you want to use an existing field or reference as the contents of a dynamic variable, you can use the [[DynamicField%601_(Component)|DynamicField<T>]] or [[DynamicReference%601_(Component)|DynamicReference<T>]] components. Instead of storing something directly, they point at a field that contains a value or reference type, respectively.</translate>


<translate>(TODO: clarify value vs. reference types; I think this isn't fully correct)</translate>
<translate><!--T:25--> (TODO: clarify value vs. reference types; I think this isn't fully correct)</translate>


=== <translate>Drivers</translate> ===
=== <translate><!--T:26--> Drivers</translate> ===


<translate>You can use the contents of a dynamic variable to drive a field or reference, using the [[DynamicValueVariableDriver%601_(Component)|DynamicValueVariableDriver<T>]] and [[DynamicReferenceVariableDriver%601_(Component)|DynamicReferenceVariableDriver<T>]] components.</translate>
<translate><!--T:27--> You can use the contents of a dynamic variable to drive a field or reference, using the [[DynamicValueVariableDriver%601_(Component)|DynamicValueVariableDriver<T>]] and [[DynamicReferenceVariableDriver%601_(Component)|DynamicReferenceVariableDriver<T>]] components.</translate>


=== <translate>Unlisted types</translate> ===
=== <translate><!--T:28--> Unlisted types</translate> ===


<translate>When creating a dynamic variable component, you will be given a list of "common types". If the type you seek is not in that list, you will have to enter it by hand. See [[Complex Types in Components]].</translate>
<translate><!--T:29--> When creating a dynamic variable component, you will be given a list of "common types". If the type you seek is not in that list, you will have to enter it by hand. See [[Complex Types in Components]].</translate>


=== <translate>Warning</translate> ===
=== <translate><!--T:30--> Warning</translate> ===


<translate>Creating, duplicating, or moving a dynamic variable requires '''binding''' that variable to its space. This usually takes a small amount of time, before which the dynamic variable can appear to be present, but not be readable or writable. Therefore, if you create a dynamic variable using the [[Create Dynamic Variable`1 (ProtoFlux)|Create Dynamic Variable]] or [[Write Or Create Dynamic Variable`1 (ProtoFlux)|Write Or Create Dynamic Variable]] ProtoFlux Node, or cause it to be duplicated using the [[Duplicate Slot (ProtoFlux)|Duplicate Slot]] ProtoFlux Node, or cause it to be moved using the [[Set Parent (ProtoFlux)|Set Parent]] ProtoFlux Node, you may find it necessary to add an [[Updates Delay (ProtoFlux)|Updates Delay]] or [[Updates Delay With Value (ProtoFlux)|Updates Delay With Value]] ProtoFlux Node afterwards in order to ensure the dynamic variables have been bound by the time you use them. A delay of 1 to 3 updates usually suffices.</translate>
<translate><!--T:31--> Creating, duplicating, or moving a dynamic variable requires '''binding''' that variable to its space. This usually takes a small amount of time, before which the dynamic variable can appear to be present, but not be readable or writable. Therefore, if you create a dynamic variable using the [[Create Dynamic Variable`1 (ProtoFlux)|Create Dynamic Variable]] or [[Write Or Create Dynamic Variable`1 (ProtoFlux)|Write Or Create Dynamic Variable]] ProtoFlux Node, or cause it to be duplicated using the [[Duplicate Slot (ProtoFlux)|Duplicate Slot]] ProtoFlux Node, or cause it to be moved using the [[Set Parent (ProtoFlux)|Set Parent]] ProtoFlux Node, you may find it necessary to add an [[Updates Delay (ProtoFlux)|Updates Delay]] or [[Updates Delay With Value (ProtoFlux)|Updates Delay With Value]] ProtoFlux Node afterwards in order to ensure the dynamic variables have been bound by the time you use them. A delay of 1 to 3 updates usually suffices.</translate>

Revision as of 11:48, 25 January 2024


This article or section is a Stub. You can help the Resonite Wiki by expanding it.


Overview

Dynamic variables allow you to read and write data by name. This makes it easy to manage data in large systems; every bit of data is clearly labeled, and you can break data into multiple spaces to keep your systems separate.

Naming Restrictions

When using Dynamic Variables there are some restrictions and limitations on naming both spaces and variables within those spaces.

Space and Variable Names cannot contain:

Usage

Optionally, the name can be prefixed by the name of a space, terminated by a /, to choose a specific variable space to use. This is useful to distinguish between unrelated systems that all use dynamic variables.

Some valid names include:

  • Health -- no space defined, named Health
  • World/Color -- named Color, in the World space
  • MyCoolSystem/Score -- named Score, in the MyCoolSystem space

Spaces

Dynamic variables can live anywhere in or under the slot containing a DynamicVariableSpace component.

So, a variable space on the world root can be used from anywhere, whilst a variable space on your avatar can be used from anything stored in your avatar.

Variables

The simplest way to use dynamic variables is to use the DynamicValueVariable<T> and DynamicReferenceVariable<T> components. These are for value (int, float, String, etc.) and reference (Slot, User, etc.) types, respectively.

These components store a value or reference directly. If two variable components have the same name, then they will have identical contents.

Fields

If you want to use an existing field or reference as the contents of a dynamic variable, you can use the DynamicField<T> or DynamicReference<T> components. Instead of storing something directly, they point at a field that contains a value or reference type, respectively.

(TODO: clarify value vs. reference types; I think this isn't fully correct)

Drivers

You can use the contents of a dynamic variable to drive a field or reference, using the DynamicValueVariableDriver<T> and DynamicReferenceVariableDriver<T> components.

Unlisted types

When creating a dynamic variable component, you will be given a list of "common types". If the type you seek is not in that list, you will have to enter it by hand. See Complex Types in Components.

Warning

Creating, duplicating, or moving a dynamic variable requires binding that variable to its space. This usually takes a small amount of time, before which the dynamic variable can appear to be present, but not be readable or writable. Therefore, if you create a dynamic variable using the Create Dynamic Variable or Write Or Create Dynamic Variable ProtoFlux Node, or cause it to be duplicated using the Duplicate Slot ProtoFlux Node, or cause it to be moved using the Set Parent ProtoFlux Node, you may find it necessary to add an Updates Delay or Updates Delay With Value ProtoFlux Node afterwards in order to ensure the dynamic variables have been bound by the time you use them. A delay of 1 to 3 updates usually suffices.