API ReferenceGE Extensionsflowgraphnodesutil
Custom Lua (Flowgraph Node)
- **Node Name:** `Custom Lua`
Overview
- Node Name:
Custom Lua - Category:
repeat_instant - File:
extensions/flowgraph/nodes/util/customLua.lua
Create a fully custom Lua node in the flowgraph editor. Provides four code slots (work, _executionStarted, _executionStopped, onPreRender) with a sandboxed environment. Supports saving/loading from a library and custom in/out pins.
Pin Schema
No fixed pins - supports custom input and output pins added by the user via the editor.
Internals
Key Methods
| Method | Description |
|---|---|
init() | Sets up empty code slots and enables custom pins |
compile(code) | Compiles a code slot using load() with the sandboxed environment |
exec(code) | Runs a compiled code slot with pcall error handling |
work() | Executes the work code slot |
_executionStarted() | Compiles all slots, then executes _executionStarted slot |
_executionStopped() | Executes _executionStopped slot and clears environment |
onPreRender(dt, dtSim) | Executes onPreRender slot |
drawCustomProperties() | ImGui editor with code text areas, status indicators, save/load |
buildBaseEnv() | Constructs the sandboxed Lua environment |
Code Slots
| Slot | When Called |
|---|---|
work | Every frame when node has active flow input |
_executionStarted | When the project starts |
_executionStopped | When the project stops |
onPreRender | Before each render frame |
Sandboxed Environment
The environment includes access to:
- Node:
self(the node instance, withself.pinIn/self.pinOut) - Core:
map,be,FS,path,scenetree,Engine,guihooks,extensions,settings - Math:
vec3,quat,quatFromEuler,clamp,round,lerp,smoothstep, etc. - Tables:
pairs,ipairs,deepcopy,shallowcopy,tableKeys,tableContains - IO:
print,dump,readFile,writeFile,jsonReadFile,jsonWriteFile - Drawing:
debugDrawer,ColorF,ColorI - ImGui:
im(ui_imgui) - All loaded extensions via
refreshExtensions()
Library System
Nodes can be saved to/loaded from a persistent library stored in editor preferences (flowgraph.general.customLuaNodes).
How It Works
- User writes Lua code in the editor's text areas for each slot.
- Code is compiled with
load()using the sandboxed environment - errors shown with red icon. self.pinInandself.pinOutare accessible viaselfin the environment.- Custom pins can be added for inputs/outputs - they're automatically serialized.
- Errors during execution are caught by
pcalland logged to the flowgraph event system.
Usage Example
-- In the "work" code slot:
local speed = be:getObjectByID(self.pinIn.vehId.value):getVelocity():length()
self.pinOut.speed.value = speed
-- In "_executionStarted":
self.myCounter = 0
-- In "work":
self.myCounter = self.myCounter + 1
self.pinOut.count.value = self.myCounter
-- Access extensions:
local mission = gameplay_missions_missions.getMissionById("myMission")
self.pinOut.missionName.value = translateLanguage(mission.name, mission.name)Key Dependencies
load()- Lua code compilationbuildBaseEnv()- sandboxed environment construction- Editor preferences - library save/load persistence
See Also
- Route Distance (Flowgraph Node) - Related reference
- Closest Road (Flowgraph Node) - Related reference
- Distance Between (Flowgraph Node) - Related reference
- FlowGraph Guide - Guide