move-to

 

move-to allows a turtle to set its x and y coordinates to be the same as another turtle or patch without altering the turtle's other variables (e.g., heading, color, size). For example, if we were working on a model of people moving between houses, where both houses and families were represented with a house, we would write the following code:

ask families [
    if my-house != nobody [
        set my-house one-of houses
        move-to my-house
    ]
]

In the model example below, we have a simple environment. Some of our patches are brown, which represents earth, and some are blue, which represents water. We have some bugs in this environment and they need to only move on the brown patches. First, we use the move-to primitive in the setup procedure to make each bug be placed on a random brown patch. Second, we use the move-to primitive (instead of forward) to make sure that our bugs pick a random neighboring brown patch and move to it.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the move-to primitive:
 
 
Similar primitives:
setxy

Moves a turtle to the exact location defined by the provided x and y coordinates.

Read more
set

Changes the value of a variable (global, local, or agent-owned).

Read more
max-pxcor

Reports the largest x-coordinate of the patches in a model.

Read more
patches

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

Read more
 
Learn another primitive: