CodeBlock escape

The DSL covers most simple rules. For anything that needs loops, multi-step state changes, or genuine helper code, set the do field to a CodeBlock.

In the editor, toggle the CodeBlock (TS escape) checkbox above the Monaco editor. The body now accepts JavaScript-shaped code with the agent's scope auto-injected - you can use energy directly, no self. prefix needed.

Example: flocking

const others = neighbors_of_type('boid');
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 targetHeading = Math.atan2(sy, sx) * 180 / Math.PI;

// turn 10% of the way toward the average
self.heading = self.heading + 0.1 * (targetHeading - self.heading);
forward(1);

What's allowed

What's banned

The CodeBlock runs in a sandbox proxy; violations throw at parse time and the rule is skipped with an error toast.

Try it in the app

Everything described here works in the live editor. Open Stigmery and follow along.

Open the app →