ProtoFlux:For: Difference between revisions

From Resonite Wiki
m fix types
move async link to see also
 
(One intermediate revision by the same user not shown)
Line 16: Line 16:
]
]
|}}
|}}
The For node is used to perform looping operations. allowing to fire impulses a set amount of times. As well as outputting the current iteration count.


For the async variant. See [[ProtoFlux:ASync For|Async For]]
The '''For''' node is used to perform looping operations by allowing one to fire impulses a set amount of times.


== Inputs ==
== Inputs ==


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


When an impulse is received. It triggers the for node. Starting the loop.
Begin the for loop.


=== Count ([[Type:Int|Int]]) ===
=== Count ([[Type:Int|Int]]) ===


sets the number of iterations the for loop will run for. The count is evaluated before the <code>LoopStart</code> impulse is fired and the count cannot be changed during the loop. The default is 0.
The amount of times to trigger <code>LoopIteration</code>. Will not trigger any iterations if less than 1.


=== Reverse ([[Type:Bool|Bool]]) ===
=== Reverse ([[Type:Bool|Bool]]) ===


Controls whether the <code>Iteration</code> increases or decreases for each <code>LoopIteration</code>. The default is false.
If <code>True</code>, the <code>Iteration</code> output will start at <code>Count - 1</code> and go down towards <code>0</code>.


== Outputs ==
== Outputs ==
Line 38: Line 37:
=== LoopStart ([[Impulses|Call]]) ===
=== LoopStart ([[Impulses|Call]]) ===


Fires once immediately after <code>*</code> is pulsed. completing the connected node chain before the loop starts and any impulses are fired from <code>LoopIteration</code>. Allowing for operations to be done before the loop.
Fires after <code>*</code> is pulsed and before any iterations are done. Will be pulsed even if <code>Count < 1</code>.


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


Fires impulses sequentially until the total amount equals <code>Count</code>. No impulses will be fired if <code>Count</code> is 0 or a negative number. the impulse chain will complete before the next <code>LoopIteration</code> is fired. unless there is any type of async delay in the chain. causing it to execute up until the delay before firing the next impulse.
Fires for each iteration of the loop. This impulse is triggered <count>Count</code> amount of times and the next iteration will only be fired once the current iteration's [[context]] is finished.


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


Fires once after the loop is completed. Allowing the execution chain to continue. Allowing for operations to be done after the loop has been completed.
Fires after the final <code>LoopIteration</code> completes execution.


=== Iteration ([[Type:Int|Int]]) ===
=== Iteration ([[Type:Int|Int]]) ===


Outputs the current iteration of the loop. Updates every time <code>LoopIteration</code> is fired. If <code>Reverse</code> is false. Iteration will start at 0 and increase each loop. ending at <code>Count - 1</code>. If <code>Reverse</code> is true. it will start at <code>Count - 1</code> and decrease each loop. ending at 0.
For each <code>LoopIteration</code>, this output is set to be the index of the iteration for said iteration's context. By default, this will start at <code>0</code> and increment until <code>Count - 1</code> unless <code>Reverse</code> is <code>True</code>.


If <code>Count</code> is '''5''' and <code>Reverse</code> is '''false'''. The iteration during the loop would be <code>0, 1, 2, 3, 4</code>
== Examples ==


And if <code>Reverse</code> is '''true'''. The iteration would be <code>4, 3, 2, 1, 0</code>
== Examples ==
<gallery widths="480" heights="480">
<gallery widths="480" heights="480">
File:For node example.png|Using the '''for''' node to iteratively check if a child slot has the tag 'foo'. and replace it with 'bar' using the [[Children Count (ProtoFlux)|Children Count]] and [[Get Child (ProtoFlux)|Get Child]] nodes.
File:For node example.png|Using the '''for''' node to iteratively check if a child slot has the tag 'foo'. and replace it with 'bar' using the [[Children Count (ProtoFlux)|Children Count]] and [[Get Child (ProtoFlux)|Get Child]] nodes.
</gallery>
</gallery>
== See Also ==
* [[ProtoFlux:Async For]] for the [[async]] variant of this node.
[[Category:ProtoFlux:Flow]]
[[Category:ProtoFlux:Flow]]

Latest revision as of 19:11, 15 December 2024

For
*
LoopStart
Count
LoopIteration
Reverse
LoopEnd
iteration
Flow

The For node is used to perform looping operations by allowing one to fire impulses a set amount of times.

Inputs

* (Call)

Begin the for loop.

Count (Int)

The amount of times to trigger LoopIteration. Will not trigger any iterations if less than 1.

Reverse (Bool)

If True, the Iteration output will start at Count - 1 and go down towards 0.

Outputs

LoopStart (Call)

Fires after * is pulsed and before any iterations are done. Will be pulsed even if Count < 1.

LoopIteration (Call)

Fires for each iteration of the loop. This impulse is triggered <count>Count amount of times and the next iteration will only be fired once the current iteration's context is finished.

LoopEnd (Continuation)

Fires after the final LoopIteration completes execution.

Iteration (Int)

For each LoopIteration, this output is set to be the index of the iteration for said iteration's context. By default, this will start at 0 and increment until Count - 1 unless Reverse is True.

Examples

See Also