Switch Case (Flowgraph Node)
- **Node Name:** `Switch Case`
Overview
- Node Name:
Switch Case - Category:
logic - File:
extensions/flowgraph/nodes/logic/switchcase.lua
Compares an input value against multiple case values and routes flow to the matching output. Equivalent to a switch/case statement.
Pin Schema
Input Pins
| Pin | Type | Description |
|---|---|---|
flow | flow | Inflow for this node |
value | any | The value to match against |
value_1 | any | Case value 1 |
Additional
value_Ninput pins created via Count property.
Output Pins
| Pin | Type | Description |
|---|---|---|
flow | flow | Outflow (always active) |
none | flow | Flow when no case matches |
match_1 | flow | Flow when value_1 matches |
Additional
match_Noutput pins created via Count property.
Behavior
init()- Sets count to 1.work()- Iterates through all case values. Ifvalue_N == value, setsmatch_Nto true. If no match, setsnoneto true. Flow always passes through.updatePins(old, new)- Dynamically adds/removesvalue_N/match_Npin pairs.drawCustomProperties()- UI for adjusting the case count.
How It Works
The node performs equality comparison (==) between the input value and each value_N case. All matching cases fire simultaneously (not just the first). If none match, the none output fires. The main flow output always passes through regardless of matching.
Example Usage
-- Route based on vehicle type:
-- value = vehicleType (string)
-- value_1 = "car", match_1 → handle car logic
-- value_2 = "truck", match_2 → handle truck logic
-- value_3 = "bus", match_3 → handle bus logic
-- none → unknown vehicle type
-- Equivalent Lua:
if value == "car" then -- match_1
elseif value == "truck" then -- match_2
elseif value == "bus" then -- match_3
else -- none
endAdditional Methods
C:_executionStarted()
Called when graph execution starts. Used for initialization/reset.
C:_onDeserialized(res)
Called after the node is deserialized (loaded from file). Restores runtime state from saved data.
Parameters:
res
C:_onSerialize(res)
Called when the node is serialized (saved to file). Returns data to persist.
Parameters:
res
C:drawMiddle(builder, style)
Custom ImGui drawing in the middle section of the node in the editor.
Parameters:
builderstyle
See Also
- And (Flowgraph Node) - Related reference
- Boolean Expression (Flowgraph Node) - Related reference
- Branch (Flowgraph Node) - Related reference
- FlowGraph Guide - Guide