Switch on String
The Switch on String node allows you to control the flow of your spell based on the value of a string input. It’s useful when you need to execute different paths or actions depending on specific string conditions.Inputs
flow(required): The input flow that triggers the node.selection(required): The string value to switch on. This input determines which output flow will be activated.
Outputs
default: The default output flow that is triggered if none of the specified cases match theselectioninput.- Additional outputs can be dynamically added based on the
numCasesconfiguration.
Configuration
numCases: Specifies the number of additional output cases to generate. Each case represents a possible string value to match against theselectioninput.
Usage
- Connect the input
flowto the desired trigger or previous node in your spell. - Set the
selectioninput to the string value you want to switch on. This can be a hardcoded string or a dynamic value from another node. - Configure the
numCasesoption to specify the number of additional output cases you need. - For each generated output case, provide a string value that represents the condition for that case.
- Connect the appropriate output flows to the corresponding nodes or actions you want to execute based on the matched case.
- If none of the specified cases match the
selectioninput, thedefaultoutput flow will be triggered.
Example
Suppose you have a spell that processes user input and you want to perform different actions based on the input value. You can use the Switch on String node to handle different cases:Best Practices
- Use clear and descriptive case values to make your spell more readable and maintainable.
- Consider using variables or expressions to set the
selectioninput dynamically based on other nodes or conditions. - Ensure that you handle all possible cases to avoid unexpected behavior. Use the
defaultoutput for cases that don’t match any specified condition.
Common Issues
- Make sure the
selectioninput is of type string. The Switch on String node only works with string values. - Double-check the spelling and case sensitivity of your case values to ensure proper matching.
- If you need to switch on non-string values, consider using other switch nodes like Switch on Number or Switch on Boolean.
