API ReferenceGE Extensionsflowgraphnodesmacro
Foreach (Flowgraph Node)
- **Node Name:** `Foreach`
Overview
- Node Name:
Foreach - Category:
logic - File:
extensions/flowgraph/nodes/macro/foreach.lua
Creates and runs a separate flowgraph instance for each element in a table. Each instance receives the key and value via the foreach module.
Pin Schema
Input Pins
| Pin | Type | Description |
|---|---|---|
flow | flow | Inflow for this node |
table | table | The table to iterate over (generic tableType) |
elementFile | string | Path to the .flow.json file to load for each element |
Output Pins
None.
Data Properties
| Property | Type | Default | Description |
|---|---|---|---|
destroyTargetOnStop | bool | true | Destroy spawned flowgraph managers when execution stops |
Behavior
init(mgr, ...)- SetsdestroyTargetOnStopto true, clears targets list.postInit()- Configures theelementFilepin to accept.flow.jsonfiles.work()- On first flow, iterates the input table. For each key/value pair, loads a flowgraph manager from the element file, setsmgr.modules.foreach.keyand.value, starts execution, and stores the manager reference._executionStopped()- IfdestroyTargetOnStopis true, stops and removes all spawned managers.
How It Works
This node is a macro-level iterator. When triggered, it loads a separate flowgraph project file for each element in the table. Each spawned flowgraph gets the current key and value injected into its foreach module, accessible via the Get Foreach node inside the child flowgraph.
The node only executes once per flow activation (tracked by self.done).
Example Usage
-- Iterate over a list of vehicle IDs:
-- table = {101, 102, 103}
-- elementFile = "/flowgraphs/processVehicle.flow.json"
-- Creates 3 flowgraph instances, each with:
-- mgr.modules.foreach.key = 1/2/3
-- mgr.modules.foreach.value = 101/102/103
-- Inside processVehicle.flow.json, use a "Get Foreach" node
-- to access the key and value for that iterationSee Also
- Get Foreach (Flowgraph Node) - Related reference
- Integrated (Flowgraph Node) - Related reference
- I/O (Flowgraph Node) - Related reference
- FlowGraph Guide - Guide