Boolean Expression (Flowgraph Node)
- **Node Name:** `Boolean Expression`
Overview
- Node Name:
Boolean Expression - Category:
simple - File:
extensions/flowgraph/nodes/logic/booleanExpression.lua
Evaluates a user-defined boolean expression using input pin values as variables. Supports template expressions (AND, OR, XOR, NAND) and custom expressions.
Pin Schema
Input Pins
| Pin | Type | Description |
|---|---|---|
a | bool | A term of the expression |
b | bool | A term of the expression |
Additional input pins are auto-created when links are added (named
c,d, etc.).
Output Pins
| Pin | Type | Description |
|---|---|---|
value | bool | The result of the calculation |
Data Properties
| Property | Type | Default | Description |
|---|---|---|---|
expression | string | "" | The boolean expression to evaluate |
safeMode | bool | true | If true, skips evaluation when any active input is nil |
Template Expressions
| Name | Expression | Description |
|---|---|---|
| AND | a and b | True if both a and b are true |
| OR | a or b | True if either a or b is true |
| XOR | (a and not b) or (b and not a) | True if exactly one is true |
| NAND | not (a and b) | True if a and b are not both true |
Behavior
init()- Sets up safe mode, empty expression, builds the sandboxed environment, and initializes caches.work()- In safe mode, skips if any connected input is nil. Parses the expression on first use or change, then evaluates viapcall. Setsvalueoutput to the result.parseExpression()- Validates the expression string (no assignments, only boolean keywords), then loads it in a sandboxed environment usingload().buildBaseEnv()- Creates a Lua environment with a metatable that reads pin input values by name.onLink(link)- Auto-creates a new boolean input pin when all existing pins are connected._executionStarted()- Builds the list of pins that have active links for safe mode checking.
How It Works
The node dynamically compiles a Lua boolean expression string into a function. Pin values are exposed as variables (a, b, c, ...) through a metatable-based environment. The expression is only re-parsed when it changes, and execution is wrapped in pcall for safety.
Example Usage
-- In a flowgraph: set expression to "a and b"
-- Connect two boolean sources to pins a and b
-- Output "value" will be true only when both inputs are true
-- Custom expression with 3 inputs:
-- expression = "a or (b and not c)"
-- Automatically creates pin c when linkedAdditional Methods
C:_onDeserialized(nodeData)
Called after the node is deserialized (loaded from file). Restores runtime state from saved data.
Parameters:
nodeData
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
C:onUnlink(link)
Called when a pin is unlinked from another node.
Parameters:
link
See Also
- And (Flowgraph Node) - Related reference
- Branch (Flowgraph Node) - Related reference
- Bundle (Flowgraph Node) - Related reference
- FlowGraph Guide - Guide