MicroWorlds EX™ Lessons
Lesson Six: Creating and Commanding Multiple Turtles
It is easy to create more turtles. The hard part is making sure which one you are commanding at the moment, and keeping your instructions separate and well-organized for each turtle.
A) How do I create Multiple Turtles?
It is easy to create turtles: Just click on the little button with egg icon where a turtle is crawling out of the egg to "Hatch a new turtle".
B) Naming & Directing Different Turtles
As you create turtles, they are specifically attached to each page of your project. So, you might have four turtles on page2 and only one on page3. You might have a T1 on page2 and a T1 on page3 and these are different turtles. Therefore, it is sometimes a good idea to rename turtles as they are created. Just right click on a turtle and choose Edit. Then, you can rename the turtle immediately to T3, T4 or whatever number you are up to in your project. This will save you trouble later when you THINK you are giving instructions to the T1 on page3 and the T1 on page6 starts carrying out those orders.
Just as in English grammar, we speak to turtles using direct address:
Bobby, sit down and be quiet, you rotten kid! (By saying the student's name first, it is clear which student the teacher is addressing.)
T1, repeat 30 [setsh 19 fd 10 wait 1 setsh 20 fd 10 wait 1] (By saying the turtle's name first, it is clear which turtle the programmer is addressing.)
So, to speak to a specific turtle, just type its name and a comma at the beginning of a line. If you do this, the same turtle will listen to you until you specifically address a different turtle by name.
C) Talking to Multiple Turtles Simultaneously
To talk to any number of turtles at the same time AND to give them the IDENTICAL commands, use the Talkto [ ] command. For example,
Talkto [ T1 T2 T3 ] repeat 36 [ square lt 10 ]
This command will first alert turtles T1, T2 & T3 to be ready to follow whatever command(s) come next. All 3 turtles will do the exact same thing. If they start out in the same spot, it will appear as if only one turtle is carrying out the command. You might have to set the position and direction of these three turtles separately first, then give this one command to be carried out. (Notice that there are no commas between the turtle names in the Talkto command.)
D) Talking to Multiple Turtles Consecutively
You can address multiple turtles consecutively like this:
T1, repeat 36 [ square lt 10 wait 1]
T2, pu seth 270 repeat 30 [setsh 19 fd 10 wait 1 setsh 20 fd 10 wait 1]
T3, wait 30 setpos [ 50 -50 ] setsh 89
These three commands should work just fine, but even if you place them in one procedure, T1 will have to complete its entire command line before T2 even starts. And then, T2 must complete all of its work before T3 even starts. To get around this sequencing, you will need to learn the launch [ ] command.
launch [ T1, repeat 36 [ square lt 10
wait 1] ]
launch [ T2, pu seth 270 repeat 30 [setsh 19 fd
10 wait 1 setsh 20 fd 10 wait 1] ]
T3, wait 30 setpos [ 50 -50 ] setsh 89
Notice that the launch command requires the use of brackets [ ] and ALL of
the instructions for each turtle should be inside that set of brackets. (Note
the red brackets above which are
paired up for T1 and the green
ones for T2.)
Also, note that the final command in any of these launch sequences does not
need the launch command. As a matter of fact, putting the launch command in
on the last one may cause the page to turn or the show to end before all of
the other procedures have finished. See Lesson Nine
for more info on multiple pages and turning pages.
E) How Do I Stop All These Turtles?
Stopall Stops all turtles and procedures. You can achieve the same result by using the mouse and pulling down Edit and clicking on Stop All
Lesson Nine: Multiple Pages In One Project
| HTS Home | | | Calendar | | | Classes | | | Departments | | | Resources | | | What's New? | Newsletter |