clear-turtles

 

clear-turtles is a primitive that removes all the turtles from the model. You can also use its shorthand version cp in your code.

clear-turtles is only used when we do not want to use clear-all. For example, if you wanted to remove the turtles but keep some global variables’ values and/or the keep the patch colors the same, you would use clear-turtles.

In the model example below, we have three buttons. The first one makes patches' color green and creates some cows on random positions. The second button runs the clear-patches primitive to clear the patches, as a proxy for grass, but leave the cows the same. The third button runs the clear-turtles primitive to remove the cows from the model but leave the patches/grass as is.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the clear-turtles primitive:
 
 
Similar primitives:
clear-all

Clears all the drawings, turtles, plots, etc., leaving a blank slate.

Read more
clear-patches

Clears the patches by resetting all patch variables to their default initial values and making them black.

Read more
die

Removes a turtle or link from the world.

Read more
reset-ticks

Sets the tick counter to 0.

Read more
 
Learn another primitive: