Skip to main content

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 lets you build if/then rules without writing code.

Rules

Each rule has three parts:

  1. IF — a condition (same as Condition node: variable + operator + value, or compound AND/OR)
  2. THEN — actions to execute (set, increment, decrement, toggle, reset variables)
  3. 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 handle
  • return or no return — follow the default output (or first edge)

Available APIs

  • Math.* — all Math functions (Math.random(), Math.floor(), etc.)
  • String(), Number(), Boolean() — type conversion
  • parseInt(), parseFloat() — number parsing
  • JSON.parse(), JSON.stringify() — JSON handling
  • Array.* — 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:

  1. Variables: All project variables with editable test values. Change values to simulate different game states.
  2. Run button: Executes the logic with your test values
  3. Result: Shows which output was selected and which variables changed (old → new)
  4. 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 branches
  • win / lose — combat/challenge outcomes
  • path_a / path_b / path_c — story branches

When to Use Logic vs. Other Nodes

NeedBest Node
Simple variable check (one condition)Condition node
Set one variableSetVariable node
Multiple conditions + actions + branchesLogic node (visual)
Complex math / random with weightsLogic node (code)
Player choiceChoice node