Rules
A rule has three fields:
- name - for display in the navigator and the change log.
- when - a DSL expression that returns true/false. When omitted or
blank, the rule always runs.
- do - what to do when
whenis true. Either a DSL expression or a
code block (see below).
A simple rule
name: eat_grass
when: patch_here().grass > 0
do: self.energy = self.energy + 4; patch_here().grass = 0
Toggling a rule
Every rule has an enabled flag. Disabling a rule keeps it visible in the navigator but skips it during ticks - useful for A/B tests.
Scopes recap
- setup_rules - initialization. Run once at Setup. No
self. - go_rules - per-tick global. No
self. - agent_type.rules - per-agent.
selfis the current agent. - patches.rules - per-patch.
selfis the current patch.
Try it in the app
Everything described here works in the live editor. Open Stigmery and follow along.
Open the app →