Skip to main content

4.4) Working With Agentsets (WITH, OF)


Two further primitives are often used in combination with agentsets, with and of.

The command “with” is one of many primitives that subsets an agentset. For example the following statement asks all blue turtles to move. This is very handy and often used but the syntax is not intuitive, so use the dictionary to get syntax correct!

ask turtles with [color = blue] [move]

The command “of” is a primitive for getting a value from another agent. The following statement for example sets the own variable happiness to the value of the happiness variable of a-neighbour-turtle.

set happiness [happiness] of a-neighbor-turtle

When applied to agentsets “of” provides a list of values. The following example uses the primitive min to select the minimal happiness value of all neighbours and set my personal happiness variable to that value.

set happiness min [happiness] of neighbors