The Switch checks an input value and executes the correct output based on it.
You can add or delete outputs, and change how the Switch selects a case.
Edit | Add cases or change the switch mode between Number Switch, Number Range Switch and Probability Distribution |
Execute | Executes the node |
↳ On Start | Executes the node at the start of the game |
Enabled | Enable or disable the node. Disabled nodes cannot be executed |
Seed | Sets a seed for random number generation *Seed is only visible if the Switch mode is set to Probability Distribution |
Value | The value that determines which output will be executed. *Value input is needed if you're using the Number or Number Range Switch mode |
Cases / Weights | Each Case or Weight output sends a signal if it's chosen by the Switch |
Default | Sends a signal if the input doesn't match any of the Cases |
By tapping Edit you can change the switch mode between Number Switch, Number Range Switch and Probability Switch, as well as add or delete cases.
In this mode the Switch uses whole numbers as the input. The node will select the case that is equal to the input value.
Example: The Switch receives the value 2 from a Number node. Output of Case 2 will send a signal.
Each case is defined with a value range. The Switch checks whether the input matches one of these ranges and chooses the equivalent case.
Example: The Switch has three cases, defined with values 2.0, 5.0 and 8.0. The ranges of these cases are 0.0 - 2.0, 2.0 - 5.0 and 5.0 - 8.0. The Switch receives the input value 4.2. This value is in the range 2.0 - 5.0, so the output of the second case will send a signal.
No input values are required from other nodes. When executed, the Switch randomly chooses one of the cases. The chosen case will send a signal from its output. For each case, you specify a weight, which determines how likely that case is to be selected.
Example: The Switch has three cases with weights: 1, 1, and 2. The first two cases are equally likely, while the last case is twice as likely. This results in probabilities of 25%, 25%, and 50%, adding up to 100%.
Here's a link to a demo that shows how to use the Switch node: