Dynamic Variables/fr: Difference between revisions

From Resonite Wiki
Updating to match new version of source page
No edit summary
Line 3: Line 3:
== Aperçu ==
== Aperçu ==


<span class="mw-translate-fuzzy">Les '''variables dynamiques''' vous permettent de lire et écrire des information depuis un simple nom. Elles rendent simple la gestion de données dans des systèmes larges; chaque bout de données est étiquetée correctement que vous pouvez décomposer en plusieurs '''espaces'''.</span>
Les '''variables dynamiques''' vous permettent de lire et écrire des information depuis un simple nom. Elles rendent simple la gestion de données dans des systèmes larges; chaque bout de données est étiquetée correctement que vous pouvez décomposer en plusieurs '''espaces'''.


== Restrictions de noms ==
== Restrictions de noms ==
Line 37: Line 37:
=== Variables ===
=== Variables ===


<span class="mw-translate-fuzzy">La manière la plus simple d'utiliser les variables dynamiques est d'utiliser les composants [[DynamicValueVariable%601_(Component)|DynamicValueVariable<T>]] et [[DynamicReferenceVariable%601_(Component)|DynamicReferenceVariable<T>]]. Ils fonctionnent pour des valeurs (int, float, String...) et references (Slot, Utilisateur...).</span>
La manière la plus simple d'utiliser les variables dynamiques est d'utiliser les composants [[DynamicValueVariable%601_(Component)|DynamicValueVariable<T>]] et [[DynamicReferenceVariable%601_(Component)|DynamicReferenceVariable<T>]]. Ils fonctionnent pour des valeurs (int, float, String...) et references (Slot, Utilisateur...).
   
   
Ces components stockent une valeur ou référence directement. Si deux variable ont le même nom, elles auront des valeurs identiques.
Ces components stockent une valeur ou référence directement. Si deux variable ont le même nom, elles auront des valeurs identiques.
Line 43: Line 43:
=== Champs ===
=== Champs ===


<div class="mw-translate-fuzzy">
Si vous voulez utiliser un champ ou référence comme contenu d'une variable dynamique, vous pouvez utiliser les composants [[DynamicField%601_(Component)|DynamicField<T>]] ou [[DynamicReference%601_(Component)|DynamicReference<T>]]. A la place de stocker quelque chose directement, ils pointent a un champ contenant une certaine valeur ou référence.
Si vous voulez utiliser un champ ou référence comme contenu d'une variable dynamique, vous pouvez utiliser les composants [[DynamicField%601_(Component)|DynamicField<T>]] ou [[DynamicReference%601_(Component)|DynamicReference<T>]]. A la place de stocker quelque chose directement, ils pointent a un champ contenant une certaine valeur ou référence.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 55: Line 53:
=== Pilotes ===
=== Pilotes ===


<span class="mw-translate-fuzzy">Vous pouvez utiliser le contenu d'une variable dynamique pour piloter un champ ou référence en utilisant les composants [[DynamicValueVariableDriver%601_(Component)|DynamicValueVariableDriver<T>]] ou [[DynamicReferenceVariableDriver%601_(Component)|DynamicReferenceVariableDriver<T>]].</span>
Vous pouvez utiliser le contenu d'une variable dynamique pour piloter un champ ou référence en utilisant les composants [[DynamicValueVariableDriver%601_(Component)|DynamicValueVariableDriver<T>]] ou [[DynamicReferenceVariableDriver%601_(Component)|DynamicReferenceVariableDriver<T>]].


=== Types non-listés ===
=== Types non-listés ===
Line 63: Line 61:
===  <span lang="en" dir="ltr" class="mw-content-ltr">Binding</span> ===
===  <span lang="en" dir="ltr" class="mw-content-ltr">Binding</span> ===


<div lang="en" dir="ltr" class="mw-content-ltr">
<span lang="en" dir="ltr" class="mw-content-ltr">Creating, duplicating, or moving a dynamic variable requires '''binding''' that variable to a space.</span>
Creating, duplicating, or moving a dynamic variable requires '''binding''' that variable to a space.  
<span lang="en" dir="ltr" class="mw-content-ltr">This is a process that happens automatically but isn't perfect yet. (see [[#Warning|Warning]])</span>
This is a process that happens automatically but isn't perfect yet. (see [[#Warning|Warning]])
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span lang="en" dir="ltr" class="mw-content-ltr">In essence it starts searching for a matching dynamic variable space at the slot of the dynamic variable.</span>
In essence it starts searching for a matching dynamic variable space at the slot of the dynamic variable.
<span lang="en" dir="ltr" class="mw-content-ltr">If there is no match, it tries the parent slot, its parent etc. until a matching space is found.</span>
If there is no match, it tries the parent slot, its parent etc. until a matching space is found.
<span lang="en" dir="ltr" class="mw-content-ltr">Variables with explicitly given space names only match spaces with the same name.</span>
Variables with explicitly given space names only match spaces with the same name.
<span lang="en" dir="ltr" class="mw-content-ltr">Variables without explicit space name match all spaces that are not <code>OnlyDirectBinding</code></span>
Variables without explicit space name match all spaces that are not <code>OnlyDirectBinding</code>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span lang="en" dir="ltr" class="mw-content-ltr">The following image will demonstrate the differences in binding:</span>
The following image will demonstrate the differences in binding:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
[[File:Dynamic_Variables.svg|border|<span lang="en" dir="ltr" class="mw-content-ltr">an image demonstrating that dynamic variable spaces with enabled OnlyDirectBinding are ignored except by variables which have explicitly declared the same space name</span>]]
[[File:Dynamic_Variables.svg|border|an image demonstrating that dynamic variable spaces with enabled OnlyDirectBinding are ignored except by variables which have explicitly declared the same space name]]
* I: <code>A</code> is connected to <code>Inner</code> because <code>Inner</code> is <u>not</u> <code>OnlyDirectBinding</code>.
* II/III: Both variables are bound explicitly.
* IV: <code>A</code> ignores <code>Inner</code> because <code>Inner</code> is <code>OnlyDirectBinding</code>.
* V/VI: Both variables are bound explicitly.
* VII/IX: There is no matching dynamic variable space. Both variables are not bound.
* VIII: The variable is explicitly bound to <code>World</code>.
* I and II share the same value.
* III, IV and VI share the same value.
</div>


* <span lang="en" dir="ltr" class="mw-content-ltr">I: <code>A</code> is connected to <code>Inner</code> because <code>Inner</code> is <u>not</u> <code>OnlyDirectBinding</code>.</span>
* <span lang="en" dir="ltr" class="mw-content-ltr">II/III: Both variables are bound explicitly.</span>
* <span lang="en" dir="ltr" class="mw-content-ltr">IV: <code>A</code> ignores <code>Inner</code> because <code>Inner</code> is <code>OnlyDirectBinding</code>.</span>
* <span lang="en" dir="ltr" class="mw-content-ltr">V/VI: Both variables are bound explicitly.</span>
* <span lang="en" dir="ltr" class="mw-content-ltr">VII/IX: There is no matching dynamic variable space. Both variables are not bound.</span>
* <span lang="en" dir="ltr" class="mw-content-ltr">VIII: The variable is explicitly bound to <code>World</code>.</span>
* <span lang="en" dir="ltr" class="mw-content-ltr">I and II share the same value.</span>
* <span lang="en" dir="ltr" class="mw-content-ltr">III, IV and VI share the same value.</span>


{{#mermaid:flowchart BT
{{#mermaid:flowchart BT
Line 145: Line 135:
=== Attention ===
=== Attention ===


<span class="mw-translate-fuzzy">Créer, dupliquer ou bouger des variables dynamiques demande de '''lier''' cette variable a son espace. Ceci est généralement rapide, pendant ce temps, la variable n'est ni lisible, ni inscriptible. Quand vous créez une variable dynamique en utilisant [[Create Dynamic Variable`1 (ProtoFlux)|Create Dynamic Variable]] ou [[Write Or Create Dynamic Variable`1 (ProtoFlux)|Write Or Create Dynamic Variable]], ou dupliquez le slot avec [[Duplicate Slot (ProtoFlux)|Duplicate Slot]], ou bougez le slot avec [[Set Parent (ProtoFlux)|Set Parent]], vous devez dans certains cas ajouter un délais avec [[Updates Delay (ProtoFlux)|Updates Delay]] ou [[Updates Delay With Value (ProtoFlux)|Updates Delay With Value]] pour attendre correctement que les variables sont liées correctement quand vous voulez les lires. Généralement un delais de 1 a 3 ticks est assez.</span>
<span lang="en" dir="ltr" class="mw-content-ltr">In a few use-cases, binding may take a small amount of time, before which the dynamic variable can appear to be present, but not be readable or writable.</span>
<span lang="en" dir="ltr" class="mw-content-ltr">Therefore, if you create a dynamic variable using the [[ProtoFlux:Create Dynamic Variable|Create Dynamic Variable]] or [[ProtoFlux:Write Or Create Dynamic Variable|Write Or Create Dynamic Variable]] ProtoFlux Node, or cause it to be duplicated using the [[ProtoFlux:Duplicate Slot |Duplicate Slot]] ProtoFlux Node, or cause it to be moved using the [[ProtoFlux:Set Parent|Set Parent]] ProtoFlux Node, you may find it necessary to add an [[ProtoFlux:Updates Delay|Updates Delay]] or [[ProtoFlux:Updates Delay With Value|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.</span>


TODO: more precise list of problematic uses cases (e.g. <code>Duplicate Slot</code> of a whole space works totally fine.)
<!-- TODO: more precise list of problematic uses cases (e.g. <code>Duplicate Slot</code> of a whole space works totally fine.) -->


==  <span lang="en" dir="ltr" class="mw-content-ltr">Example Applications</span> ==
==  <span lang="en" dir="ltr" class="mw-content-ltr">Example Applications</span> ==


The following examples will demonstrate a few use-cases of dynamic variables.
<span lang="en" dir="ltr" class="mw-content-ltr">The following examples will demonstrate a few use-cases of dynamic variables.</span>
There is a focus on how to use them to create separate objects
<span lang="en" dir="ltr" class="mw-content-ltr">There is a focus on how to use them to create separate objects</span>


===  <span lang="en" dir="ltr" class="mw-content-ltr">Modules within an object</span>  ===
===  <span lang="en" dir="ltr" class="mw-content-ltr">Modules within an object</span>  ===


<div lang="en" dir="ltr" class="mw-content-ltr">
Dynamic variables within an object allow modularization.
Different modules would be connected via dynamic variables within the space located at the root of the object.
If all hard-coded references going in or out of a module are eliminated you can replace it with a different variant/version without additional setup.
Module-local variables can be created with a dynamic variable space located at the root of the module. Use appropriately named spaces to differentiate between the two.
To make available variables more obvious to other people - including you in 6 months - it is recommended to place all dynamic variables within a dedicated slot hierarchy.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span lang="en" dir="ltr" class="mw-content-ltr">Dynamic variables within an object allow modularization.</span>
Commonly used names for such hierarchies are:
<span lang="en" dir="ltr" class="mw-content-ltr">Different modules would be connected via dynamic variables within the space located at the root of the object.</span>
<span lang="en" dir="ltr" class="mw-content-ltr">If all hard-coded references going in or out of a module are eliminated you can replace it with a different variant/version without additional setup.</span>
<span lang="en" dir="ltr" class="mw-content-ltr">Module-local variables can be created with a dynamic variable space located at the root of the module. Use appropriately named spaces to differentiate between the two.</span>
<span lang="en" dir="ltr" class="mw-content-ltr">To make available variables more obvious to other people - including you in 6 months - it is recommended to place all dynamic variables within a dedicated slot hierarchy.</span>
 
<!--T:42-->
<span lang="en" dir="ltr" class="mw-content-ltr">Commonly used names for such hierarchies are:</span>
* DV
* DV
* DynVar
* DynVar
* Vars
* Vars
* etc.
* etc.
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
<span lang="en" dir="ltr" class="mw-content-ltr">A modular object could look like this:</span>
A modular object could look like this:
* Project (<span lang="en" dir="ltr" class="mw-content-ltr">Space: <code>MyProject</code></span>)
* Project (Space: <code>MyProject</code>)
** Dynamic Variables
** Dynamic Variables
*** projectVar: String (Dynamic variable <code>projectVar</code> of type [[Type:String|String]])
*** projectVar: String (Dynamic variable <code>projectVar</code> of type [[Type:String|String]])
** Module: UI (i.e. [[Component:MeshRenderer|MeshRenderer]] or [[Component:Canvas|Canvas]] plus [[Collider|Colliders]]), may contain:
** Module: <span lang="en" dir="ltr" class="mw-content-ltr">UI (i.e. [[Component:MeshRenderer|MeshRenderer]] or [[Component:Canvas|Canvas]] plus [[Collider|Colliders]]), may contain:</span>
*** Dynamic Variable Drivers → Visuals
*** Dynamic Variable Drivers → Visuals
*** [[:Category:Components:Common_UI:Button_Interactions|Button Interactions]] → Dynamic Variables
*** [[:Category:Components:Common_UI:Button_Interactions|Button Interactions]] → Dynamic Variables
Line 183: Line 172:
*** Dynamic Variables
*** Dynamic Variables
**** logicVar: int (Dynamic variable <code>logicVar</code> of type [[Type:Int|int]])
**** logicVar: int (Dynamic variable <code>logicVar</code> of type [[Type:Int|int]])
**** MyProject/Logic: Slot (Dynamic variable <code>Logic</code> of type [[Slot]] for space <code>MyProject</code>, driven with reference to Slot of module to make it accessible to other modules)
**** MyProject/Logic: <languages/>Slot (Dynamic variable <code>Logic</code> of type [[Slot]] for space <code>MyProject</code>, driven with reference to Slot of module to make it accessible to other modules)
*** [[ProtoFlux]] (may read, write or even drive dynamic variables of space <code>MyProject</code>)
*** [[ProtoFlux]] <span lang="en" dir="ltr" class="mw-content-ltr">(may read, write or even drive dynamic variables of space <code>MyProject</code>)</span>
</div>


===  <span lang="en" dir="ltr" class="mw-content-ltr">Configurable objects</span>  ===
===  <span lang="en" dir="ltr" class="mw-content-ltr">Configurable objects</span>  ===
<div lang="en" dir="ltr" class="mw-content-ltr">
Dynamic variables make it possible to access other object's properties.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span lang="en" dir="ltr" class="mw-content-ltr">Dynamic variables make it possible to access other object's properties.</span>
Assuming objects with a dynamic variable space, a collider and a string variable named <code>Description</code> you could then create a separate tool that reads and displays the <code>Description</code> of the object it is pointed at. The same tool could be extended to edit descriptions.
 
</div>
<span lang="en" dir="ltr" class="mw-content-ltr">Assuming objects with a dynamic variable space, a collider and a string variable named <code>Description</code> you could then create a separate tool that reads and displays the <code>Description</code> of the object it is pointed at. The same tool could be extended to edit descriptions.</span>
 
<span lang="en" dir="ltr" class="mw-content-ltr">The same concept can also be applied to template slots used within a project.</span>
<span lang="en" dir="ltr" class="mw-content-ltr">Their instances can be interacted with using dynamic variables.</span>


<div lang="en" dir="ltr" class="mw-content-ltr">
The same concept can also be applied to template slots used within a project.
Their instances can be interacted with using dynamic variables.
</div>
===  <span lang="en" dir="ltr" class="mw-content-ltr">World/User variables</span>  ===
===  <span lang="en" dir="ltr" class="mw-content-ltr">World/User variables</span>  ===
<div lang="en" dir="ltr" class="mw-content-ltr">
There are already pre-made dynamic variable spaces:
* <code>World</code> on [[Root]] (<code>OnlyDirectBinding</code>)
* <code>User</code> on each [[Component:UserRoot|User Root]] Slot (<code>OnlyDirectBinding</code>)
* <code>Dash</code> on Slot of [[Component:UserspaceRadiantDash|UserSpaceRadiantDash]]
They can be used for states that are shared by many objects (i.e. day/night toggle, performance) or to broadcast information into the world. ([[BeatLink]], library objects like the [[Redprint]] manager)
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span lang="en" dir="ltr" class="mw-content-ltr">There are already pre-made dynamic variable spaces:</span>
See [[Dynamic Variable Naming Standard]] for a more detailed listing.
* <span lang="en" dir="ltr" class="mw-content-ltr"><code>World</code> on [[Root]] (<code>OnlyDirectBinding</code>)</span>
</div>
* <span lang="en" dir="ltr" class="mw-content-ltr"><code>User</code> on each [[Component:UserRoot|User Root]] Slot (<code>OnlyDirectBinding</code>)</span>
* <span lang="en" dir="ltr" class="mw-content-ltr"><code>Dash</code> on Slot of [[Component:UserspaceRadiantDash|UserSpaceRadiantDash]]</span>
<span lang="en" dir="ltr" class="mw-content-ltr">They can be used for states that are shared by many objects (i.e. day/night toggle, performance) or to broadcast information into the world. ([[BeatLink]], library objects like the [[Redprint]] manager)</span>
 
 
<span lang="en" dir="ltr" class="mw-content-ltr">See [[Dynamic Variable Naming Standard]] for a more detailed listing.</span>

Revision as of 22:35, 24 April 2024

Aperçu

Les variables dynamiques vous permettent de lire et écrire des information depuis un simple nom. Elles rendent simple la gestion de données dans des systèmes larges; chaque bout de données est étiquetée correctement que vous pouvez décomposer en plusieurs espaces.

Restrictions de noms

En utilisant les variables dynamiques, il y a quelques restrictions sur le nommage sur les variables et espaces.

Les noms de variables et espaces ne peuvent pas contenir:

Which concept or properties do your spaces and variables represent? Take your time to name them appropriately!
Those names will be used in different places or even by multiple users. Changing them after the fact can become quite challenging.

Utilisation

Optionnellement, un nom de variable peut être préfixé avec le nom d'un espace, se finissant avec /, pour choisir un espace de variables. Cela est utile pour distinguer des systèmes indépendants.

Quelques noms valides incluent:

  • Vie -- pas d'espaces, juste nommé Vie
  • World/Couleur -- nommé Couleur, dans l'espace World
  • MonSysteme/Score -- Nommé Score, dans l'espace MonSysteme

Espaces

Les variables dynamiques peuvent être n'importe ou ou sous un slot contenant le composant DynamicVariableSpace.

Donc, une variable sur l'origine du monde peut être utilisée de partout alors qu'une variable dans un espace sur votre avatar ne peut être utilisée que sur votre avatar.

Variables

La manière la plus simple d'utiliser les variables dynamiques est d'utiliser les composants DynamicValueVariable<T> et DynamicReferenceVariable<T>. Ils fonctionnent pour des valeurs (int, float, String...) et references (Slot, Utilisateur...).

Ces components stockent une valeur ou référence directement. Si deux variable ont le même nom, elles auront des valeurs identiques.

Champs

Si vous voulez utiliser un champ ou référence comme contenu d'une variable dynamique, vous pouvez utiliser les composants DynamicField<T> ou DynamicReference<T>. A la place de stocker quelque chose directement, ils pointent a un champ contenant une certaine valeur ou référence.

As with variables there is a variant for Type fields: DynamicTypeField

(A FAIRE: clarifier les types valeur vs référence)

Pilotes

Vous pouvez utiliser le contenu d'une variable dynamique pour piloter un champ ou référence en utilisant les composants DynamicValueVariableDriver<T> ou DynamicReferenceVariableDriver<T>.

Types non-listés

A la création d'une variable dynamique, vous pouvez choisir depuis une liste de types communs. Si ce que vous voulez n'est pas dans la liste, vous allez devoir entrer le type complexe manuellement.

Binding

Creating, duplicating, or moving a dynamic variable requires binding that variable to a space. This is a process that happens automatically but isn't perfect yet. (see Warning)

In essence it starts searching for a matching dynamic variable space at the slot of the dynamic variable. If there is no match, it tries the parent slot, its parent etc. until a matching space is found. Variables with explicitly given space names only match spaces with the same name. Variables without explicit space name match all spaces that are not OnlyDirectBinding

The following image will demonstrate the differences in binding:

an image demonstrating that dynamic variable spaces with enabled OnlyDirectBinding are ignored except by variables which have explicitly declared the same space name

  • I: A is connected to Inner because Inner is not OnlyDirectBinding.
  • II/III: Both variables are bound explicitly.
  • IV: A ignores Inner because Inner is OnlyDirectBinding.
  • V/VI: Both variables are bound explicitly.
  • VII/IX: There is no matching dynamic variable space. Both variables are not bound.
  • VIII: The variable is explicitly bound to World.
  • I and II share the same value.
  • III, IV and VI share the same value.

Attention

In a few use-cases, binding may take 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.


Example Applications

The following examples will demonstrate a few use-cases of dynamic variables. There is a focus on how to use them to create separate objects

Modules within an object

Dynamic variables within an object allow modularization. Different modules would be connected via dynamic variables within the space located at the root of the object. If all hard-coded references going in or out of a module are eliminated you can replace it with a different variant/version without additional setup. Module-local variables can be created with a dynamic variable space located at the root of the module. Use appropriately named spaces to differentiate between the two. To make available variables more obvious to other people - including you in 6 months - it is recommended to place all dynamic variables within a dedicated slot hierarchy.

Commonly used names for such hierarchies are:

  • DV
  • DynVar
  • Vars
  • etc.

A modular object could look like this:

  • Project (Space: MyProject)
    • Dynamic Variables
      • projectVar: String (Dynamic variable projectVar of type String)
    • Module: UI (i.e. MeshRenderer or Canvas plus Colliders), may contain:
    • Module: Logic (Space: Logic)
      • Dynamic Variables
        • logicVar: int (Dynamic variable logicVar of type int)
        • MyProject/Logic:
  • français
  • русский

Slot (Dynamic variable Logic of type Slot for space MyProject, driven with reference to Slot of module to make it accessible to other modules)

      • ProtoFlux (may read, write or even drive dynamic variables of space MyProject)

Configurable objects

Dynamic variables make it possible to access other object's properties.

Assuming objects with a dynamic variable space, a collider and a string variable named Description you could then create a separate tool that reads and displays the Description of the object it is pointed at. The same tool could be extended to edit descriptions.

The same concept can also be applied to template slots used within a project. Their instances can be interacted with using dynamic variables.

World/User variables

There are already pre-made dynamic variable spaces:

They can be used for states that are shared by many objects (i.e. day/night toggle, performance) or to broadcast information into the world. (BeatLink, library objects like the Redprint manager)


See Dynamic Variable Naming Standard for a more detailed listing.