Loops
Repeat, ranges, lists, and the two condition-driven loops.
7 min readEvery loop node has two outputs. body runs once per
iteration; done continues after the loop finishes. Wire the
work to body and whatever comes next to done.
| Node | Use it for |
|---|---|
| Repeat | A fixed number of times, counting from 0 |
| For Range | Counting from one number to another, with a step |
| For Each | Walking a list, or every entity with a tag |
| For In | The keys of an object, or the indexes of a list |
| While | Repeat while something stays true (may run zero times) |
| Do While | The same, but always runs at least once |
| For Each With Tag | The original shorthand for tag iteration |
Loop variables
Each loop writes its counter or current item into a variable you name, so
nodes inside the body can read it. For Each also binds
self to the current item when that item is an entity, which
means entity nodes inside the body work with no target set.
Where the list comes from
For Each takes its list from one of three places, chosen with the List from dropdown:
variable— a variable holding a list. A name that does not exist is an empty list, not a one-item list containing the name.tag— every live entity carrying that tag.literal— a comma-separated list typed straight in, likered, green, blue.
The iteration limit
If a loop hits that limit it stops and writes a warning to the browser console naming the node. If you see a loop finishing early, that is the first thing to check.
A worked example
On Scene Start
└─ Repeat (times: 8, count into: i)
body ─→ Spawn (x: "100 + i * 60", y: 80, tag: enemy)
done ─→ Banner ("WAVE 1")
Eight enemies, evenly spaced, then a banner. The x field is
an expression — anywhere a number is accepted you can write one, and any
variable name in it is substituted.