Terrapin Resources
Multiple Turtles

ALLTURTLES     SETTURTLES     TURTLES     TELL     WHO     TELLEVEN     TELLODD
EACH     ASK     CTURTLES     LTURTLES     SETTURTLENAME     TURTLENAMES     TURTLENAME

In this section, you will learn about commands to use more than one turtle. This ability will lead you to all kinds of fun projects!


ALLTURTLES


ALLTURTLES reports a list of all available turtles. When Logo first starts up, there are 16 turtles available.

If you type ALLTURTLES, you will see this result:

ALLTURTLES
Result: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]

Notice that the first turtle is number 0. It is the active turtle when you first start Logo.

» Things to Try

Every now and then, after you have started using different sets of turtles, type ALLTURTLE to confirm which turtles are available.


SETTURTLES number
SETT number


SETTURTLES defines the number of turtles to be available, starting with 0. The last available turtle is the number you enter as input minus 1.

SETTURTLES 6
ALLTURTLES
Result: [0 1 2 3 4 5]

The SETTURTLES command doesn’t change the active turtle. When you start Logo, the active turtle is 0.

Even though you have 6 turtles available after you give the SETTURTLES 6 command, only turtle 0 will follow your instructions.

Read on to learn how to talk to more than one turtle.

Be aware that giving a SETTURTLES command after you have given turtles different shapes will reset them all to the standard turtle shape. (Remember that you can always click the Undo button or type UNDO a few times to get your turtles back with their special shapes.)

» Things to Try

Try setting different numbers of turtles and see the result of ALLTURTLES.


TURTLES


TURTLES reports the number of turtles that are available.

Think of it as counting how many numbers are in the list reported by ALLTURTLES.

» Things to Try

Try typing TURTLES. What is the result?

Now type this:
TURTLES = COUNT ALLTURTLES

Do you get a True or False result? Do you see how these two commands — TURTLES and ALLTURTLES — are tied together?


TELL number
TELL list-of-numbers


TELL actives the turtle or turtles you specify by number. The turtle or list of turtles will now follow all your commands.

You can’t give a number higher than the current number of available turtles. Suppose you enter SETTURTLES 10.
If you type TELL 12 you will get an error message. Try it and see what the message says.

All the turtles will appear at their home in the center of the drawing canvas. But all of them except the first active turtle, probably turtle 0, are hidden. To make them all be visible (after they are no longer in the same spot), type:
TELL ALLTURTLES ST

To see them you will need to move them apart.

You can use CTURTLES or LTURTLES, or talk to each one individually using WHO and EACH. Read more below for information about these commands.

» Things to Try

Remember that you can type ALLTURTLES to see the numbers of the turtles that are currently available.

Use TELL 2 to talk to an individual one, in this case turtle 2, or give a list of turtle numbers, such as TELL [0 1 2].


WHO


WHO reports the list of turtles that you have activated.

TELL [0 2 4 5]
WHO
Result: [0 2 4 5]

You can use WHO in many ways, especially with EACH. Read more below about these commands.

» Things to Try


TELLEVEN


TELLEVEN sets the active turtles to the even-numbered ones.

SETTURTLES 8
TELLEVEN
WHO
Result: [0 2 4 6]

You can use WHO at any time to see which turtles are active.

» Things to Try

Set different numbers of turtles with SETTURTLES.

Then type TELLEVEN and then WHO to see the results.


TELLODD


TELLODD sets the active turtles to the odd-numbered ones.

SETTURTLES 8
TELLODD
WHO
Result: [1 3 5 7]

You can use WHO at any time to see which turtles are active.

Note that turtle 0 is an even number. If only turtle 0 is active and you type TELLODD, you will see an error message.

» Things to Try

Set different numbers of turtles with SETTURTLES.

Then type TELLODD and then WHO to see the results.


EACH list-of-commands


EACH tells all active turtles to run a list of commands.

You can use it with WHO to get different turtles to perform an action based on their turtle number. For example:

SETTURTLES 8
TELL ALLTURTLES
SHOWTURTLE RIGHT 90
EACH [FORWARD WHO * 30]

In this example:
Turtle 0 doesn’t move because 0, its turtle number, times 30 = 0.
Turtle 1 goes forward 30 because its “WHO” number is 1 and 1 times 30 = 30.
Turtle 2 goes forward 60 because its “WHO” number is 2 and 2 times 30 = 60.
and so on, until turtle 7 goes forward 210.

You could also have put the SHOWTURTLE and RIGHT 90 instructions inside the list after EACH.

This picture shows of the result of these instructions.

» Things to Try

Try using WHO and EACH together to get different results.

Can you get your turtles to turn different amounts based on their “WHO” value, which is their turtle number?


ASK number-or-list [list-of-commands]


ASK allows you to talk to a specific turtle or turtles and give them a command or get information from them without changing the active turtles in your TELL list. You can give an inactive turtle an instruction using ASK.

For example, you can type this to see if turtle 3 is showing?

ASK 3 [SHOWN?]

Or you could turn turtle 8 the opposite way.

ASK 8 [RIGHT 180]

» Things to Try


CTURTLES number


CTURTLES arranges the active turtle in a circle. In addition to arranging the turtles in a circle, it also sets the number of turtles to 8, makes them active, and puts their pens down.

CTURTLES 8    

Entering a FD 30 command gives you the result in the second image above:

» Things to Try

The CTURTLES command is a shortcut. You could write down a set of instructions that do the same thing.

Can you figure out what those instructions would be?

Try some more experiments with CTURTLES.


LTURTLES number


LTURTLES creates the number of turtles you specify and places them in a line, like this:

If you want to move them based on their turtle number, you can use the WHO and EACH commands, like this:

The image below shows the result of these instructions:

LTURTLES 7
EACH [FD 15 * WHO]

Turtle 0 goes forward 15, turtle 1 goes forward 30, etc.

This next image below shows the result of these instructions:

LTURTLES 7
EACH [FD 15 XCOR]

The x-coordinate, reported by XCOR is the distance from home the turtle is. Turtles to the left of home have a negative XCOR value. Those to the right of home have a positive XCOR value.

You can ASK each turtle what its XCOR value is by typing an instruction like this:

ASK 0 [XCOR] or ASK 4 [XCOR]

That will show you how far each turtle moved. Remember that FD -50 is the same as BK 50.

» Things to Try

The LTURTLES command is a shortcut. You could write down a set of instructions that do the same thing.

Can you figure out what those instructions would be?

Try some more experiments with LTURTLES.


SETTURTLENAME word
SETTNAME word


SETTURTLENAME allows you to name your turtles.

To make this image, you would create 3 turtles with SETTURTLES 3.
You can use LTURTLES 3 to line them up.
Move the turtles apart so they won’t overlap. Move turtle 0 with this set of commands: TELL 0 PU LT 90 FD 150 RT 90
Move turtle 2 to the right with this: TELL 2 PU RT 90 FD 150 LT 90
Now, drag a shape from the Animals category in the Toolbox to each turtle. (The Toolbox is in the Window menu.)

Why not give these turtles names so you don’t have to remember which one has which number? That is when SETTURTLENAME comes in handy.

SETTURTLENAME 0 "SNAIL
SETTURTLENAME 1 "TURTLE
SETTURTLENAME 2 "RABBIT

To create a name, which is a word, start with a quotation mark before the name (but not after).

Now you can talk to each turtle using its name, like this:

TELL "TURTLE LT 90 FD 100
TELL "RABBIT RT 90 FD 200

You can’t give two turtles the same name. If you name two turtles the same by accident, rename one of them “XXX and then you can rename both of the them to what you want.

Even after you have named your turtles, you can still refer to them by their numbers. In this case, these instructions both set the active turtle to the same one:

TELL "SNAIL
TELL 0

You can talk to more than one named turtle by putting them in a list, like this:

TELL [SNAIL RABBIT]


TURTLENAMES


TURTLENAMES reports a list of the names of active turtles in order, starting from turtle 0.

TURTLENAMES
Result: [SNAIL TURTLE RABBIT]

» Things to Try

Try making different sets of turtles active and see what TURTLENAMES reports.


TURTLENAME
TNAME


TURTLENAME reports the name of first active turtle.

TELL ALLTURTLES
TNAME 0
Result: SNAIL
TELL 2
TNAME 0
Result: RABBIT

The reason that TNAME reports different turtle names in the example above is that when all 3 turtles are active, the first one, turtle 0, is named "SNAIL. After you use TELL 2 to talk to the rabbit, it is the only active turtle, and that is why its name is reported. It is now Turtle 0.

It may be a little confusing at first, but after some experimentation, you’ll see how it works!

Note that WHO reports the turtle numbers, not their names.

» Things to Try

Experiment with turtle names using different shapes.