Compare (Flowgraph Node)
- **Node Name:** `Compare`
Overview
- Node Name:
Compare - Category:
logic - File:
extensions/flowgraph/nodes/logic/compare.lua
Compares two values using a selectable comparison operator (==, ~=, <, >, <=, >=) and outputs the boolean result along with flow routing.
Pin Schema
Input Pins
| Pin | Type | Description |
|---|---|---|
flow | flow | Inflow for this node |
A | any | First value for comparison |
B | any | Second value for comparison |
Output Pins
| Pin | Type | Description |
|---|---|---|
flow | flow | Outflow for this node |
true | flow | Flow when comparison returns true |
false | flow | Flow when comparison returns false |
value | bool | The boolean result of the comparison (hidden) |
Data Properties
The comparison operator is selected via a dropdown in the node's custom properties UI, using getComparisonOps().
Behavior
init()- Sorts available comparison operators and selects the first one as default.work()- ComparesAandBusing the selected operator. For<,>,<=,>=: if either operand is nil, logs an error and outputs false. For==/~=: nil operands are allowed.refreshFunction()- Updates the comparison function reference when the operator changes._onSerialize(res)/_onDeserialized(res)- Persists the selected operator symbol.
How It Works
The node uses getComparisonOps() to get a table of comparison functions with their symbols. The selected function is called on each work() tick with the two input values. The result routes flow to either the true or false output pin.
The middle of the node displays the current operator symbol (e.g., ==, >).
Example Usage
-- Compare player speed against a threshold:
-- A = currentSpeed (number)
-- B = 50 (hardcoded number)
-- Operator: >=
-- Result: true flow if speed >= 50
-- Equivalent Lua:
local result = (A >= B)
if result then
-- true branch
else
-- false branch
endAdditional Methods
C:_onPropertyChanged(key, val)
Called when a node property is changed in the editor.
Parameters:
keyval
C:drawCustomProperties()
Custom ImGui drawing for the node's properties panel in the editor.
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