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 when is true. Either a DSL expression or a code block (see below).

A simple rule

name:  eat_grass
when:  patch().grass > 0
do:    energy = energy + 4; patch().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. self is the current agent.
  • patches.rules - per-patch. self is the current patch.