Switch
Picks one of two values with a condition, evaluating only that one.
Node id logic/switch
The Switch node outputs then when condition is true, and else when
it is false: "if … then … else" in a graph.
Inputs
| Name | Type | Default | Notes |
|---|---|---|---|
| condition | boolean | false | |
| then | T | — | lazygeneric |
| else | T | — | lazygeneric |
Outputs
| Name | Type | Notes |
|---|---|---|
| result | T | generic |
Behaviour
- Only the chosen branch is evaluated.
thenandelseare lazy inputs: the nodes feeding the branch that isn't picked don't run at all. A failing node there doesn't make Switch fail, and a heavy one costs nothing. - Any type.
then,elseandresultare generic pins of the same type: the first wire connected to one of them sets it for all three. Connect two circles, two numbers, two arrays… conditionis false by default. Connect a comparison (Greater, Equals Number…) or set it in the property inspector.- Inside a function, the condition can differ for every call: in a Map function, for example, each element can take its own branch. A subgraph call in the branch that isn't picked is not made.
- The base case of a recursion. In a subgraph that calls itself, a
Switch decides when to stop: the base case in
then, the calls inelse. See Recursion and the Sierpinski triangle.
Errors
- The chosen branch must be connected: being generic,
thenandelsecan't be set in the property inspector. "Switch: nothing connected to then" (orelse) names the missing one. The other branch may stay unconnected. - If a node of the chosen branch fails, Switch fails too and its branch is left out. The failing node is the one marked.