m ProbablePrime moved page While (ProtoFlux) to ProtoFlux:While: Creating protoflux Namespace |
Escalated the warning note to a danger note. Updated description. Fixed link. Added a suggestion note. Added a fun facts section to this page. |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
|Inputs= | |Inputs= | ||
[ | [ | ||
{"Name": "*", "Type": " | {"Name": "*", "Type": "Call"}, | ||
{"Name": "Condition", "Type": "bool"} | {"Name": "Condition", "Type": "bool"} | ||
] | ] | ||
|Outputs= | |Outputs= | ||
[ | [ | ||
{"Name": "LoopStart", "Type":" | {"Name": "LoopStart", "Type":"Call"}, | ||
{"Name": "LoopIteration", "Type":" | {"Name": "LoopIteration", "Type":"Call"}, | ||
{"Name": "LoopEnd", "Type":"Continuation"} | {"Name": "LoopEnd", "Type":"Continuation"} | ||
] | ] | ||
|}} | |}} | ||
The '''While''' node will start running when this gets [[Impulses|impulsed]]. The code will continue running and hold a [[Impulses#Context|context]] until the provided Condition is false or the max execution iterations is hit. | |||
{{Note|If this node just has an [[ProtoFlux:Call Input|Input]] with the [[Type:bool|bool]] type set to true, the code will not be able to stop and will error the entire Flux, and in many cases the entire world or client will freeze (Issues [https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/774 #774] & [https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/1677 #1677]). Caution should be exercised when using this node.|danger}} | |||
{{Note|If it is easy to determine how often the loop is going to execute, a [[ProtoFlux:For|For Loop]] should be preferred to avoid accidentally creating infinite loops.|suggestion}} | |||
== Inputs == | |||
=== * ([[Impulses|Call]]) === | |||
Impulse to start the loop | |||
=== Condition ([[Type:Bool|Boolean]]) === | |||
The value that the loop will check for if it should continue running or not. | |||
== Outputs == | |||
=== LoopStart ([[Impulses|Impulse]]) === | |||
Fires once at the beginning of the loop, regardless of if Condition ([[Type:Bool|Boolean]]) is true or not. | |||
=== LoopIteration ([[Impulses|Impulse]]) === | |||
Fires infinitely all in one game tick until the game crashes, or Condition ([[Type:Bool|Boolean]]) is false. Will only fire if Condition ([[Type:Bool|Boolean]]) is true. | |||
=== LoopEnd ([[Impulses|Impulse]]) === | |||
Fires once the triggered loop has ended and the node has not hit a critical error. | |||
== Examples == | |||
<gallery widths=480px heights=480px> | |||
File:Protoflux_example_while_loop.webp|Example of how to use a while loop. | |||
File:Protoflux_example_while_loop_failed.webp|Example of how to not use a while loop, which will crash the game if fired. | |||
</gallery> | |||
== Further Reading == | |||
=== Fun Facts === | |||
This node (and even more broadly, code with loops like these in general) has an [[Unsolvable Problem]], specifically the [https://en.wikipedia.org/wiki/Halting_problem halting problem]. | |||
[[Category:ProtoFlux:Flow]] | [[Category:ProtoFlux:Flow]] |
Latest revision as of 14:00, 11 July 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.
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.