Escalated the warning note to a danger note. Updated description. Fixed link. Added a suggestion note. Added a fun facts section to this page. |
Add Known Issues section to document issue #256 |
||
Line 51: | Line 51: | ||
File:Protoflux_example_while_loop_failed.webp|Example of how to not use a while loop, which will crash the game if fired. | File:Protoflux_example_while_loop_failed.webp|Example of how to not use a while loop, which will crash the game if fired. | ||
</gallery> | </gallery> | ||
== Related Issues == | |||
* As the time of writing, there is [https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/256 a known issue] that can occur when the very last node in the LoopIteration chain is a [[ProtoFlux:Write|Write]] node. If the Write affects the value of a variable which is itself used as part of the evaluation of the Condition, the evaluation will use the value that the variable held ''before'' the Write operation is completed. | |||
** Because this only occurs if the Write node is the very last one in the chain, a simple workaround is to connect any node to the OnWritten output of the Write node – such as a [[Tips & Tricks#Quickly create inputs or displays|Pulse Display]]. | |||
== Further Reading == | == Further Reading == |
Revision as of 14:29, 13 December 2024
While
Flow
The While node will start running when this gets impulsed. The code will continue running and hold a context until the provided Condition is false or the max execution iterations is hit.
Inputs
* (Call)
Impulse to start the loop
Condition (Boolean)
The value that the loop will check for if it should continue running or not.
Outputs
LoopStart (Impulse)
Fires once at the beginning of the loop, regardless of if Condition (Boolean) is true or not.
LoopIteration (Impulse)
Fires infinitely all in one game tick until the game crashes, or Condition (Boolean) is false. Will only fire if Condition (Boolean) is true.
LoopEnd (Impulse)
Fires once the triggered loop has ended and the node has not hit a critical error.
Examples
-
Example of how to use a while loop.
-
Example of how to not use a while loop, which will crash the game if fired.
Related Issues
- As the time of writing, there is a known issue that can occur when the very last node in the LoopIteration chain is a Write node. If the Write affects the value of a variable which is itself used as part of the evaluation of the Condition, the evaluation will use the value that the variable held before the Write operation is completed.
- Because this only occurs if the Write node is the very last one in the chain, a simple workaround is to connect any node to the OnWritten output of the Write node – such as a Pulse Display.
Further Reading
Fun Facts
This node (and even more broadly, code with loops like these in general) has an Unsolvable Problem, specifically the halting problem.