Nodes

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 the selection input.
  • Additional outputs can be dynamically added based on the numCases configuration.

Configuration#

  • numCases: Specifies the number of additional output cases to generate. Each case represents a possible string value to match against the selection input.

Usage#

  1. Connect the input flow to the desired trigger or previous node in your spell.
  2. Set the selection input to the string value you want to switch on. This can be a hardcoded string or a dynamic value from another node.
  3. Configure the numCases option to specify the number of additional output cases you need.
  4. For each generated output case, provide a string value that represents the condition for that case.
  5. Connect the appropriate output flows to the corresponding nodes or actions you want to execute based on the matched case.
  6. If none of the specified cases match the selection input, the default output 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:

1. User Input Node (output: "userInput")
   |
2. Switch on String Node
   - selection: "userInput"
   - numCases: 3
   - Case 1: "apple"
   - Case 2: "banana"
   - Case 3: "orange"
   |
   |- Case 1 -> Action A
   |- Case 2 -> Action B
   |- Case 3 -> Action C
   |- default -> Default Action

In this example, if the user input is "apple", the flow will be directed to Action A. If the input is "banana", Action B will be executed, and so on. If the user input doesn't match any of the specified cases, the flow will be directed to the Default Action.

Best Practices#

  • Use clear and descriptive case values to make your spell more readable and maintainable.
  • Consider using variables or expressions to set the selection input dynamically based on other nodes or conditions.
  • Ensure that you handle all possible cases to avoid unexpected behavior. Use the default output for cases that don't match any specified condition.

Common Issues#

  • Make sure the selection input 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.

By using the Switch on String node, you can create powerful and dynamic spells that adapt their behavior based on specific string conditions.