Rules
A rule has three fields:
- name: shown in the navigator and the change log.
- when: a DSL expression that is true or false. Leave it blank and the rule always runs.
- do: what happens when
whenis true. A DSL expression or a CodeBlock (see that chapter).
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 switch. A disabled rule stays in the navigator but does not run. Use it to compare a model with and without that rule.
Scopes recap
- setup_rules: run once at Setup. No
self. - go_rules: run once per tick for the whole model. No
self. - agent_type.rules: run for each agent.
selfis the current agent. - patches.rules: run for each patch.
selfis the current patch.