CodeBlock escape
The DSL covers most simple rules. Need loops, several steps of changes or helper code? Set the do field to a CodeBlock.
In the editor, tick the CodeBlock (TS escape) box above the code editor. The body takes JavaScript-like code and sees what a DSL expression sees. Bare names are the current agent's or patch's properties and the globals. All DSL functions work, and me is the current agent or patch.
Example: flocking-style alignment
const others = neighbors(3); // agents within 3 patches
if (others.length === 0) return;
// average heading of nearby boids
let sx = 0, sy = 0;
for (const b of others) {
sx += Math.cos(b.heading * Math.PI / 180);
sy += Math.sin(b.heading * Math.PI / 180);
}
const target = Math.atan2(sy, sx) * 180 / Math.PI;
// rotate 10% of the way toward the group's average heading
turn(0.1 * (target - heading));
move_forward(1);
What's allowed
- Assignments, conditionals, loops (
for,while), locallet/const. - The full DSL function set (
move_forward,neighbors,chance, ...). - Standard JS globals:
Math,JSON,Array,Object,Number,String,Boolean,parseInt,parseFloat,isNaN,isFinite. These are also available in regular one-line expressions.
What's banned
await/async: a rule must finish within its tick.eval,new Function(...),import(...): no loading of code.
A rule that uses them fails when it is read. It then shows a red ! error badge next to its name in the Code tab.