Logic & Scripting
The Logic node (formerly "Script") handles complex branching, variable manipulation, and custom calculations. It has two modes: Visual for rule-based logic, and Code for JavaScript.
Opening the Editor
Select a Logic node in the graph, then click "Open Logic Editor" in the inspector. This opens a fullscreen editor with:
- Left: Rules (visual) or code editor
- Right: Test panel with editable variable values, Run button, and result display
Visual Mode (Recommended)
Visual mode lets you build if/then rules without writing code.
Rules
Each rule has three parts:
- IF — a condition (same as Condition node: variable + operator + value, or compound AND/OR)
- THEN — actions to execute (set, increment, decrement, toggle, reset variables)
- OUTPUT — which output handle to follow
Rules are evaluated top to bottom. The first matching rule wins. If no rule matches, the Default output is used.
Example
Rule 1:
IF: trust > 5 AND visited_park = true
THEN: friendship += 2
OUTPUT: → good_ending
Rule 2:
IF: trust > 0
THEN: friendship += 1
OUTPUT: → neutral_ending
Default: → bad_ending
This replaces what would otherwise be 3 Condition nodes + 3 SetVariable nodes + 6 edges.
When to Use Visual Mode
- Multiple conditions leading to different branches
- Calculating values based on game state
- Complex branching that's hard to express with Condition nodes alone
- Any logic where you want to test with different variable values
Code Mode (Advanced)
Code mode provides a JavaScript editor for cases where visual rules aren't flexible enough.
Variable Access
Variables are available by their name (not ID). Read and write directly:
// Read
if (trust > 5 && visited_park) {
// Write
friendship += 2;
return "good_ending";
}
if (trust > 0) {
friendship += 1;
return "neutral_ending";
}
return "bad_ending";
Return Values
return "handleId"— follow the named output handlereturnor no return — follow the default output (or first edge)
Available APIs
Math.*— all Math functions (Math.random(), Math.floor(), etc.)String(),Number(),Boolean()— type conversionparseInt(),parseFloat()— number parsingJSON.parse(),JSON.stringify()— JSON handlingArray.*— array methods
Limitations
- No access to
window,document,fetch, or DOM - No
async/await - Code runs synchronously — avoid infinite loops
- 3-second timeout (execution is killed if it takes longer)
Testing
The right panel of the Logic Editor is a test console:
- Variables: All project variables with editable test values. Change values to simulate different game states.
- Run button: Executes the logic with your test values
- Result: Shows which output was selected and which variables changed (old → new)
- Errors: Displays any runtime errors in red
This lets you verify your logic works before running the full game.
Outputs
Add named outputs at the bottom of the editor. Each output creates a handle on the node that you can connect to different branches in the graph.
Common patterns:
good/neutral/bad— ending quality brancheswin/lose— combat/challenge outcomespath_a/path_b/path_c— story branches
When to Use Logic vs. Other Nodes
| Need | Best Node |
|---|---|
| Simple variable check (one condition) | Condition node |
| Set one variable | SetVariable node |
| Multiple conditions + actions + branches | Logic node (visual) |
| Complex math / random with weights | Logic node (code) |
| Player choice | Choice node |