Clear Terrain and Delete Everyone

Posted January 30, 2019 by miriam.brown@j…

My students keep asking why they should put a "clear terrain" and "delete everyone" blocks at the beginning of their code.  The video said it was best practices, but I'm still not quite sure what that refers to.  It seems like if the program is new there would be no terrain to clear and no agents to delete.  I'm pretty new at this so I appreciate any help I can get.

Comments

Submitted by sgibbs on Wed, 01/30/2019 - 12:44 · Permalink

Hi Miriam, thanks for your question.  You are correct that those blocks don't make a difference when you first open a model and run it.  However, people almost never run a model only once.  Instead, they run the model multiple times, either to see what happens when you change the code (like changing the turn angle in flower turtles, which gives you a different shape) or to run multiple experiments.  "Clear terrain" isn't strictly necessary when the terrain isn't changed in a model (the background stays green and the agents never have their pen down), but it is necessary if any changes to the terrain occur while running the model.  "Delete everyone" is necessary to make sure you get the number of agents that your setup code creates -- for example, if you leave this block out of the flower turtles setup code, you will create 5 turtles the first time you push setup.  You will create 5 additional turtles the next time you push setup.  Both codes help to reset the program to the original settings, so the next run of the model starts with everything the same as the previous one.  

I hope this helps to answer you question, please write back if you have other questions.