setxy

 

setxy moves a turtle to the given coordinates in the world. For example, if we wanted to create a house and put it on a specific location, we would write the following code:

create-turtles 1 [
    set shape "house"
    setxy 
]

Things to keep in mind when using setxy:

In the model example below, setxy is used with two user-inputted values to place a chess piece at a chosen place on the chess board. You can imagine how essential setxy would be to creating an actual game of chess in NetLogo.

Note: The "chess board" in this model is 7 squares by 7 squares instead of the traditional 8 by 8. This was done for the sake of example because by default, NetLogo encourages worlds with odd edge lengths to make sure that the center is always at (0,0) and the overall world is symmetrical. To make this "chess board" the proper size, go into the settings panel found in the interface tab and change the location of the origin (another word for the center of the world) to "Custom". There you can change the max-pxcor and min-pycor both to 4. Voila, an actual chess board.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

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

Moves a turtle to set its x and y coordinates to be the same as another turtle or patch.

Read more
min-pxcor

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

Read more
max-pycor

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

Read more
neighbors

Reports an agentset containing the eight neighboring patches.

Read more
 
Learn another primitive: