Nodes
Branch#
The Branch node allows you to conditionally route the flow of your spell based on a boolean condition. It's a fundamental control flow node that enables you to create decision points and execute different paths depending on whether the condition evaluates to true or false.
Inputs#
flow
(required): The incoming flow that will be routed based on the condition.condition
(required): A boolean value that determines which output the flow will be routed to. Default value isfalse
.
Outputs#
true
: The flow will be routed to this output if thecondition
input istrue
.false
: The flow will be routed to this output if thecondition
input isfalse
.
Configuration#
This node has no additional configuration options.
Usage#
- Connect the incoming flow to the
flow
input of the Branch node. - Connect a boolean value representing your desired condition to the
condition
input. This can come from a variable, an expression, or the output of another node. - Connect the
true
output to the node(s) you want to execute when the condition is true. - Connect the
false
output to the node(s) you want to execute when the condition is false. - The flow will be routed based on the value of the
condition
input at runtime.
Example#
Suppose you have a spell that processes a list of numbers and you want to perform different actions based on whether the list is empty or not. Here's how you could use the Branch node:
- Use a List node to define your list of numbers.
- Connect the List node to a "Is Empty" node to check if the list is empty.
- Connect the "Is Empty" node's boolean output to the
condition
input of a Branch node. - If the list is empty (condition is true), connect the
true
output to a Log node with the message "The list is empty". - If the list is not empty (condition is false), connect the
false
output to a "For Each" node to iterate over the list and perform some processing.
Best Practices#
- Keep your conditions simple and focused. If you find yourself needing complex nested conditions, consider breaking your spell into smaller, more manageable sub-spells.
- Use descriptive labels for the
true
andfalse
outputs to make your spell graph easier to read and understand. - Remember that the Branch node does not modify the flow itself, it only routes it. If you need to transform the data in the flow, use other nodes before or after the Branch.
Common Mistakes#
- Forgetting to connect both the
true
andfalse
outputs. If you leave one unconnected, that branch will terminate and may lead to unexpected behavior. - Connecting non-boolean values to the
condition
input. Make sure thecondition
is always a boolean to avoid type mismatch errors.