Skip to main content

Expression

This node executes custom JavaScript expressions.

The Expression node allows you to run snippets of JavaScript code directly within the graph.

The Expression node is a powerful tool for executing custom JavaScript logic. It allows you to write a single-line or multi-line expression that returns a value. It supports dynamic inputs, meaning you can add variables to your expression (e.g., a + b) and the node will automatically create input ports for them.

Inputs​

General​

DataDescription
ExpressionThe JavaScript code to execute. This is a special input that opens a code editor. Variables used in the code (e.g., x, y, myVar) become dynamic inputs on the node.

Dynamic Inputs​

DataDescription
*Any variable name used in your expression will appear as an input port. Connect data to these ports to use them in your code.

Actions​

SignalDescription
RunTriggers the execution of the expression. If not connected, the expression runs automatically whenever any input changes.

Outputs​

Result​

DataDescription
ResultThe return value of the expression.
Is TrueBoolean: true if the result is truthy.
Is FalseBoolean: true if the result is falsy.

Events​

SignalDescription
On TrueTriggered if the result is truthy.
On FalseTriggered if the result is falsy.

Usage​

Writing Expressions​

The code you write is wrapped in a function. You should return a value.

  • Simple Math: a * b + c (Creates inputs a, b, c)
  • String Logic: firstName + " " + lastName (Creates inputs firstName, lastName)
  • Complex Logic:
    if (score > 100) {
    return "Winner";
    } else {
    return "Try Again";
    }

Available Globals​

The following Math functions are available directly without the Math. prefix:

  • min, max, round, floor, ceil, abs, random, sqrt, sin, cos, tan, pi

Auto-Run vs. Manual Run​

  • Auto-Run: If the Run input is NOT connected, the expression evaluates every time any of its data inputs change.
  • Manual Run: If you connect a signal to Run, the expression only evaluates when that signal is triggered. This is useful for expensive calculations or when you want to synchronize with a button press.

Detailed Behavior​

  1. Parsing: The node parses your code to find variable names and creates inputs for them.
  2. Scope: Inputs are injected into the function scope.
  3. Execution: The code is compiled into a function and executed safely.
  4. Error Handling: Runtime errors are logged to the console and may trigger editor warnings. The result defaults to 0 on error.

Troubleshooting​

  • Inputs Not Showing: Ensure your variable names are valid JavaScript identifiers (e.g., no spaces, don't start with numbers).
  • Result is 0: Check the console for syntax errors or runtime exceptions.
  • Infinite Loops: Avoid while(true) loops; the execution environment attempts to be safe but can still freeze if you write blocking code.