ask

 

ask is one of the foundational primitives in NetLogo. It allows us to ask one or more agents (i.e., turtles, links, patches) to follow a provided set of rules. When ask is used with more than one agents, each agent will take its turn in a random order.

For example, the following code would make all the turtles in a model to move forward one unit and all the patches in a model pink.

ask turtles [ fd 1 ] 
ask patches [ set pcolor pink ]

We can also provide more than one command with an ask primitive. For example, the following code would make all the turtles put their pen-down, and then turn right by ten degrees and go forward one unit 36 times, which would draw a circle.

ask turtles [
    pen-down
    repeat 36 [
       right 10
       forward 1
    ]
]

Things to keep in mind when using ask:

In the model below, we want the fish to swim around randomly and the stars to just rotate, and we want all the turtles (fish + stars) to grow little by little. To make them follow these actions, we just use the ask primitive !

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the ask primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Published NetLogo models that use the ask primitive:
 
 
Similar primitives:
turtles

Reports an agentset that contains all the turtles in a model.

Read more
patches

Reports an agentset that contains all the patches in a model.

Read more
links

Reports an agentset that contains all the links in a model.

Read more
with

Reports a subset of the original agentset that only contains the agents with specified characteristics.

Read more
 
Learn another primitive: