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
| Data | Description |
|---|---|
| Expression | The 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
| Data | Description |
|---|---|
| * | 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
| Signal | Description |
|---|---|
| Run | Triggers the execution of the expression. If not connected, the expression runs automatically whenever any input changes. |
Outputs
Result
| Data | Description |
|---|---|
| Result | The return value of the expression. |
| Is True | Boolean: true if the result is truthy. |
| Is False | Boolean: true if the result is falsy. |
Events
| Signal | Description |
|---|---|
| On True | Triggered if the result is truthy. |
| On False | Triggered 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 inputsa,b,c) - String Logic:
firstName + " " + lastName(Creates inputsfirstName,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
- Parsing: The node parses your code to find variable names and creates inputs for them.
- Scope: Inputs are injected into the function scope.
- Execution: The code is compiled into a function and executed safely.
- Error Handling: Runtime errors are logged to the console and may trigger editor warnings. The result defaults to
0on 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.