Skip to content
Bit Quirky Round Trip
Visual Scripting

Search documentation

All topics and APIs

Close returns focus to Search.

What are you looking for?

Try a common topic or a C# feature.

Browse the reference instead

Esc closes · Tab reaches results · Enter opens the focused link

v1.0.0
Menu

Switch

Place a switch on the canvas, wire the value it decides on, add a case for each value, and give every case its own white wire.

A switch is one yellow node that looks at a single value and sends the white wire down a different output for each value it can hold. You build it by placing the node, wiring the value in, and adding one case per value.

The switch node takes one value on its Selection pin. On its right edge it grows one exec output per case, each labeled with the value it matches, plus default when you add one and Completed, which always carries on to whatever runs after the switch. When the game runs, exactly one case output fires: the one whose label matches the value on Selection, or default when none does. If nothing matches and there is no default, the switch goes straight to Completed.

Each case owns the nodes on its own white wire. Reading the node from top to bottom tells you every value it handles and what each one does, side by side.

Reach for a switch when one thing in your game is in one of several named states and each state needs different behavior:

  • An enemy that patrols, chases, or is stunned, where each state turns movement and damage on or off.
  • A pickup that does something different per item type: a coin adds score, a heart restores health, a key opens a door.
  • A menu that reacts to which tab is selected, or a weapon that fires differently per firing mode.

If the decision is a plain yes or no, use a branch. If each path depends on a different, unrelated question, chain branches instead.

A second form, switch expression, picks a value instead of picking a path: for example, the speed to use for each enemy state. It is covered at the end of the steps.

Start in a method whose canvas holds only its magenta entry node, the node titled with the method’s name that has an Exec pin and a self pin. A new method from the + beside Methods in the left rail starts that way.

Build a switch with case paths

  1. Place a switch

    Right-click empty canvas to the right of the entry node. Pick switch under flow control, or type switch and pick the switch row.

    Clip: the all actions menu opens, the pointer searches for switch and places a yellow SWITCH node. While the pointer picks it, the switch row of the menu is highlighted, with an arrow pointing at it.
  2. Wire the entry

    Drag from the entry node’s white Exec output and drop on the switch node’s Exec input.

    Clip: a white wire is dragged from the entry node to the switch exec input. While the pointer drags, the entry node's exec output and the switch's exec input are highlighted, with an arrow pointing at them.
  3. Feed the selection

    Give the switch its value. Drag the variable it should decide on from the Variables list in the left rail onto empty canvas left of the switch, and choose get. Drag from the pill’s output pin to the switch’s Selection pin.

    Clip: the _goalUnlocked variable is dragged from the rail, chosen as get, and wired to selection. The _goalUnlocked row in the Variables rail, the get row of the menu, the dot on the pill and the switch's selection pin are highlighted in turn, each with an arrow pointing at it.
  4. Select the switch and add a case

    Click the switch node to select it. In the right rail, press Add case, or press Add pin on the node itself.

    The selected switch’s right rail shows the Switch section with no cases. The Add case button is highlighted, with an arrow pointing at it.
    The Switch section shows a new case 1 card, highlighted, with its match not yet chosen.
  5. Choose a match

    Open the matches dropdown and pick the value this case handles.

    The Switch section shows true selected as the first case match. The matches dropdown is highlighted, with an arrow pointing at it.
  6. Add the remaining cases

    Repeat Select the switch and add a case and Choose a match for every value that needs its own behavior. Use ↑ (Move earlier) and ↓ (Move later) to change the order. To catch every value you did not list, add one more case and press its ◇ (Make this the default).

    Clip: a false case and a default case are added in the switch rail. The Add case button, the matches dropdown, the Add case button again and the make-default diamond button are highlighted in turn, each with an arrow pointing at it.
  7. Place the first case’s work

    Place the work for the first case. Right-click empty canvas to the right of the switch, type the name of the method that case should call, and pick it. Drag from the first case output on the switch to the call node’s Exec input.

    Clip: a call is placed and wired to the switch true case. The SpawnCoin row of the menu, the true output, then the call's exec input are highlighted in turn, each with an arrow pointing at it.
  8. Fill and chain the call

    Fill the call node’s own pins: tick a checkbox, type a number into a literal field, or wire a pill into a colored pin. Chain more nodes after it by dragging from its Exec output to the next node’s Exec input, or drag onto empty canvas and pick the next node from the menu.

    Clip: the call’s input is filled and another call is chained to it. The call's index input, its exec output, then the AwardGold row of the menu are highlighted in turn, each with an arrow pointing at it.
  9. Wire the remaining cases

    Repeat Place the first case’s work and Fill and chain the call for each remaining case output.

    Clip: calls are placed and wired to the false and default cases. For the false case, the AwardSilver menu row, the false output and the call's exec input are highlighted in turn; for the default case, the AwardBronze menu row, the default output and that call's exec input are highlighted in turn. Each has an arrow pointing at it.
  10. Wire completed

    If something should run after the switch whichever case ran, place that node and drag a white wire to it from Completed.

    Clip: a call is placed and wired from completed. The RefreshHud menu row, the completed output, then the call's exec input are highlighted in turn, each with an arrow pointing at it.
  11. Compile

    Press Compile in the top toolbar.

    The whole Graph view window before Compile, showing this page's NewMethod draft: the entry node, a SWITCH fed by _goalUnlocked and a call on each case and on completed, with the Previewing your changes notice at the top of the right rail. The gold Compile button in the top toolbar is highlighted, with an arrow pointing at it.
    The compiled switch graph: the true case runs SpawnCoin then AwardGold, false runs AwardSilver and default runs AwardBronze; the cases join at RefreshHud, the call after the switch.

To pick a value instead of a path, place switch expression from flow control in the Place a switch step. It lands as a table with PATTERN and RESULT columns, a dashed Add case row, and FIRST MATCH WINS along the bottom. Wire the value it decides on into its selection pin, press Add case for each row, click a row’s pattern cell to choose its value from the Match on list (the last entry, Anything else, catches everything left), and type the result into the row’s RESULT cell. Then wire the node’s result into the pin that uses it, such as a SET node’s Value.

Right-click a switch and choose Edit switch cases to do the same case work in a popover beside the node: Switch cases lists every case with Add case, Remove, Move up, Move down, Make default and Clear default. It works on a switch you placed and on one that came from the script.

If you also work in C#, this is what lands in the script. The Platformer sample’s ApplyState is one switch from top to bottom, and it writes:

Each case output becomes a case label, the nodes on its wire become that case’s statements, and a new case ends with break. A case marked default becomes default:. A When guard on a case adds a when condition after its label. A switch expression writes the x switch { ... } form, with one arm per table row, into whichever pin its result is wired to. A goto case or goto default node appears when a script jumps from one case into another.

When it goes wrong

SymptomCheckFix
The matches dropdown is a plain text field with no list.Select the switch and read its type row. A note under the cases asks you to wire a value into selection.Wire a pill into selection so the rail knows the type and offers its values.
Compile refuses the switch.Select the switch and look for a case card in the right rail whose matches row still reads (not chosen).Pick a value for that case, or remove it with ×.
A value runs none of the cases.Look for a default output on the node. Without one, an unmatched value leaves through completed.Add a case and press its ◇ button to make it the default, then wire its output.
The wrong case runs.Read the case order in the right rail. The first case whose value matches is the one that runs.Use the ↑ and ↓ buttons to move the case, or check its when field.
Full-size image