Page 4 of 4
The last complication in getting to grips with NetLogo is the way variables work.
You can define a global variable that is available to every function using
and you can then use myVariable to store a value using set. For example:
You can also create a local variable within a function using the let keyword:
Local variables only exist after the let statement and if the let is within square brackets it only exists within those brackets.
Of course agents have variables and we have already been using many built in variables. You can also add your own variables to agents so that you can create custom states. Each type of agent has its own set of variables. You can add to the set of variables using something like:
This adds the new variable myTurtleVariable to every turtle. Each turtle gets its own separate new variable and can hold a value that is potentially different for all turtles. You can do the same for patches and links.
Notice that turtles and patched have a special relationship in that a turtle can access the variables of the patch it is "standing" on. For this reason turtles and patches cannot have a variable with the same name.
There is so much that we haven't covered. You need to learn about links, the third type of agent. You also need to find out more about general Logo - if, repeat, functions with parameters, and so on. NetLogo also has good facilities for building user interfaces and for presenting the results of simulations.
However, you have now been introduced to the main elements of the NetLogo language and what makes it special - and hence what makes it difficult to get started with.