ProtoFlux:Indirect Write: Difference between revisions

From Resonite Wiki
added writes template
Fixed order of descriptions. Fixed link.
 
(5 intermediate revisions by 2 users not shown)
Line 5: Line 5:
|Inputs=
|Inputs=
[
[
{"Name":"*", "Type":"Impulse"},
{"Name":"*", "Type":"Call"},
{"Name":"Variable", "Type":"Variable"},
{"Name":"Variable", "Type":"IVariable`2"},
{"Name":"Value", "Type":"Dummy"}
{"Name":"Value", "Type":"Dummy"}
]
]
Line 17: Line 17:


Indirect writes can be commonly found in legacy content that has been migrated from other platforms.
Indirect writes can be commonly found in legacy content that has been migrated from other platforms.
Indirect writes take Variable ([[Type:Variable|Variable]]) as an input, and the type that Variable wraps will determine what Value (Generic) will take as a value. The node will then write Value (Generic) to the field Variable ([[Type:Variable|Variable]]) wraps.
Indirect writes take Variable ([[Type:IVariable`2|Variable]]) as an input, and the type that Variable wraps will determine what Value (Generic) will take as a value. The node will then write Value (Generic) to the field Variable ([[Type:IVariable`2|Variable]]) wraps.


{{Template:Basic Writes Info|Indirect Writes}}
{{Template:Basic Writes Info|Indirect Writes}}


{{Template:How To Make Type Variables|Indirect Writes}}
{{Template:How To Make Type Variables|Indirect Writes}}
== Indirect Write or Write? ==
The difference between a [[ProtoFlux:Write|Write]] node and an Indirect Write is in how they reference the variable they affect.  In a Write node, what is called a [[Global]] is used to hold the variable, and this reference is only evaluated when the Protoflux starts executing.  Therefore, code that changes the variable for a normal Write during its execution will have no effect.
In contrast, an Indirect Write node uses a normal input for its variable, which is evaluated whenever the node is called.  This allows for the variable to be programmatically changed during the flow of execution, such as via a [[ProtoFlux:Multiplex|multiplexer]] with an indeterminate number of possible inputs.
In short, if you're writing to a static variable stick with normal [[ProtoFlux:Write|Write]], while if your code might change the variable you're writing to during execution use Indirect Write instead.


== Inputs ==
== Inputs ==


=== * (Call) ===  
=== * ([[Impulses|Call]]) ===  


Call this to write the value.
Call this to write the value.


=== Value (Generic) ===
=== Variable ([[Type:IVariable`2|Variable]] Generic)===


[[:Category:Type|Value]] to write to the value being wrapped by Variable [[Type:Variable|Variable]]
The [[Type:IVariable`2|Variable]] to write to.


=== Variable ([[Type:Variable|Variable]] Generic)===
=== Value (Generic) ===


The [[Type:Variable|Variable]] to write to.
[[:Category:Type|Value]] to write to the value being wrapped by Variable [[Type:IVariable`2|Variable]]


== Outputs ==
== Outputs ==


=== OnWritten (Continuation) ===
=== OnWritten ([[Impulses|Continuation]]) ===


sends an impulse after * (Call) has been impulsed and the value has been written.
sends an impulse after * ([[Impulses|Call]]) has been impulsed and the value has been written.


=== OnFail (Continuation) ===
=== OnFail ([[Impulses|Continuation]]) ===


sends an impulse after * (Call) has been impulsed and the value wasn't able to be written due to a missing target or the variable not wrapping a valid [[Type:IField`1|IField`1]]
sends an impulse after * ([[Impulses|Call]]) has been impulsed and the value wasn't able to be written due to a missing target or the variable not wrapping a valid [[Type:IValue`1|IValue`1]]


== Examples ==
== Examples ==


<gallery widths="480" heights="480">
<gallery widths=480px heights=480px>
File:Protoflux_example_multiplexing_variables.webp|How to use multiplexing on an indirect node type to switch variables using a for loop.
File:Protoflux_example_source_to_indirect_variable.webp|How to use a source to make an indirect variable.
File:ProtoFlux_Indirect_Write_Example_Basic.jpg|A basic setup for making an Indirect Write write to a field shown in the inspector.
File:ProtoFlux_Indirect_Write_Example_Basic.jpg|A basic setup for making an Indirect Write write to a field shown in the inspector.
</gallery>
</gallery>


[[Category:ProtoFlux:Actions:Indirect]]
[[Category:ProtoFlux:Actions:Indirect]]

Latest revision as of 05:01, 26 June 2024

Indirect Write
*
OnWritten
Variable
OnFail
Value
Indirect

Indirect writes can be commonly found in legacy content that has been migrated from other platforms. Indirect writes take Variable (Variable) as an input, and the type that Variable wraps will determine what Value (Generic) will take as a value. The node will then write Value (Generic) to the field Variable (Variable) wraps.

Indirect Writes are a way to change a specified value without driving it. Instead you can use Indirect Writes to change a value in a similar fashion to changing the value through the inspector. Using Indirect Writes helps with performance too, since the values provided to the node only evaluate for one game tick while the node is being impulsed vs a driver which evaluates every game tick. This can also be used to reduce the amount of times code is evaluated. If you have to search the entire root for your code to find a slot and then do an operation, using Indirect Writes with your operations will help with performance since you're only searching once and not every single game tick.

Variables for Indirect Writes can be made using a Field As Variable which can wrap any type (Generic). Variables can also be made by dragging a source of the same wrapped type (ex:Source<String> -> Variable<String>) into any variable input and it will make a special converter to connect them. This can be multiplexed using Multiplexing for using multiple variables into the same input on Indirect Writes. Multiplexing the inputs on Indirect Writes can be useful in modifying a list of variables during a For or While loop.

Indirect Write or Write?

The difference between a Write node and an Indirect Write is in how they reference the variable they affect.  In a Write node, what is called a Global is used to hold the variable, and this reference is only evaluated when the Protoflux starts executing.  Therefore, code that changes the variable for a normal Write during its execution will have no effect.

In contrast, an Indirect Write node uses a normal input for its variable, which is evaluated whenever the node is called.  This allows for the variable to be programmatically changed during the flow of execution, such as via a multiplexer with an indeterminate number of possible inputs.

In short, if you're writing to a static variable stick with normal Write, while if your code might change the variable you're writing to during execution use Indirect Write instead.

Inputs

* (Call)

Call this to write the value.

Variable (Variable Generic)

The Variable to write to.

Value (Generic)

Value to write to the value being wrapped by Variable Variable

Outputs

OnWritten (Continuation)

sends an impulse after * (Call) has been impulsed and the value has been written.

OnFail (Continuation)

sends an impulse after * (Call) has been impulsed and the value wasn't able to be written due to a missing target or the variable not wrapping a valid IValue`1

Examples