Skip to main content

3.1) Fundamental Code Parts


This section introduces first fundamental code parts and then elementary NetLogo commands.

Code of agent-based models is usually structured into four fundamental code parts (left side). (i) The declaration of variables, agents and collectives, (ii) the model initialization, (iii) the scheduled actions executed with each time step (tick), and (iv) all the sub models containing scientific and cosmetic stuff. The corresponding NetLogo code parts (right side) are explained in the following.

globals []
turtles-own []
breed [wolves wolf]
1. Declaration of variables, agents and collectives
to setup
   ask patches [do-something]
   ask turtles [do-something]
end
2. Model initialization
to go
   ask patches [do-something]
   ask turtles [do-something]
   tick
end
3. Scheduled actions (tick)
to do-something-special
end
to do-something-boring
end
4. Sub-models (science and cosmetics)