Vous êtes sur la page 1sur 49

MicroWorlds Pro

Tips and Tricks


by Gary Stager
About the Author

Gary Stager is a veteran teacher, educator, and educational


consultant currently living in Los Angeles. He is a leading
Logo evangelist and Editor-in-Chief of Logo Exchange. Gary
is an adjunct professor of education at Pepperdine University
and a Contributing Editor for Curriculum Administrator
Magazine. Mr. Stager is a frequent speaker at schools and
conferences around the world, primarily Australia where
he played a significant role in the pioneering use of laptops
in the classroom. He was the founder of the New Jersey
Educational Computing Conference and 1993 Program
Chair of the International Logo Conference in Australia.
He loves the learning opportunities afforded by Logo and
finds it as rewarding today as he did seventeen years ago.

Graphic design by Le groupe Flexidée

© Logo Computer Systems Inc. 2000


All rights reserved.

No part of the document contained herein may be reproduced, stored in


retrieval systems or transmitted, in any form or by any means,
photocopying, electronic, mechanical, recording or otherwise, without
the prior approval from Logo Computer Systems Inc.

Legal deposit, second semester 2000

ISBN 2-89371-493-5
Printed 4-00

MicroWorlds is a trademark and is a registered trademark of


Logo Computer Systems Inc. All other trademarks or registered
trademarks are the properties of their respective owners.
TABLE OF CONTENTS

Preface ....................................................................................... v

T I P S
1. Changing the Shape of a Turtle ....................................................... 1
2. Will Murray the Turtle Please Step Forward?................................ 3
3. Cloning a Turtle ............................................................................... 4
4. Graphics Galore ................................................................................ 5
5. Wordy Pictures ................................................................................. 7
6. Special Effects................................................................................... 8
7. Where Should I Click?...................................................................... 10
8. Averting Disaster.............................................................................. 12
9. Don’t Stop Me Now! ........................................................................ 14
10. Extra Pages are Your Friends........................................................... 16
11. Going Public on the Web.................................................................. 17
12. Link Up Your Project ....................................................................... 21
13. What Do Turtles Own? ................................................................... 22
14. All Together Now............................................................................. 24
15. Adding Interactivity to Your Projects.............................................. 27
16. Getting Your Messages into Shape ................................................. 30
17. Carefully Building a Simple Calculator .......................................... 31
18. Follow the Yellow Brick Road.......................................................... 33
19. When Turtles Collide ....................................................................... 36
20. Turn Your Pages .............................................................................. 38
21. Changing Your Mind ....................................................................... 40
22. Text Box Magic................................................................................. 42

iii
Preface

I
T SEEMS LIKE THE MORE YOU KNOW MICROWORLDS, the
more you want to know about MicroWorlds. Here is a book
of “secrets” that will help you learn the ins and outs of
MicroWorlds painlessly. We suggest that you read all the tips,
trying them out as you go on the computer. Even if a tip may not
seem relevant at the moment, you never know when it will come
in handy.
The tips in this book are not exhaustive. We picked some tips
which people have often asked us about, and others that are not
easily apparent in the software and documentation. The Tips
book does not replace the online Help Topics and Vocabulary. You
should check the Vocabulary to find the definition and example
of any primitive mentioned in this book. The Help topics provides
in-depth information about MicroWorlds features or concepts.
Please let us know if you like these tips, and if you have tips of
your own. You can check our web site www.LCSI.ca for sample
projects, and e-mail us at info@LCSI.ca.

v
This manual is for use with both the Windows and
Macintosh versions of MicroWorlds Pro.

The following symbols are used throughout this book:

Right-click  Control-click With Windows, Right Click is used


to open pop up menus on objects;
the same functionality is obtained
on a Mac by Control Click.
Shift key  key With Windows, the Shift key is
used to add more than one shape to
a turtle and to change the heading
of the turtle; the same functiona-
lity is obtained on a Mac with the
Command key.
T I P

1
Changing
the Shape
of a
Turtle

T
URTLES ARE ACTORS on the MicroWorlds stage. You can
have as big a cast as you like and your actors may wear
all sorts of costumes. In MicroWorlds, these costumes
are called shapes. You can design a shape and put it on the tur-
tle or you can import a picture as a shape.

WHEN

If you want to change a turtle’s costume, choose a shape


in the shapes collection of the Graphics Tab area and click
on the turtle. Shapes may be used to give the illusion of
animation. MicroWorlds uses the flip book animation
style of wear a shape, move a little, change to the next
shape, etc...

DISCUSSION

Here’s how to make a bird fly:


1. Select the first bird shape in the shapes collection.
2. Click on the turtle to change its shape.
3. Hold down the Shift key  key and select the second

bird shape in the shapes collection.


4. With the Shift key  key still down, click on the tur-
tle to change its shape.
5. Release the Shift key  key .

CHANGING THE SHAPE OF A TURTLE TIP 1 1


Now try this. Choose the Regular Pointer (the arrow) and
Right-click  Control-click on the turtle. Select Animate. Watch

the turtle!
QUESTION: What if you want the bird turtle to fly in another
direction?
ANSWER: Hold down the Shift key  key , click on the

bird turtle, and drag it in the direction that you want


it to fly. Voila!
If you have trouble “catching” the turtle to change its
direction, stop the turtle first with the stopall tool.
EXTENSIONS

Right-click  Control-click on the turtle and select Edit. When

the dialog box appears, notice the instruction that


Animate automatically inserted.
forward 5 wait 1
If you would like to change the speed that the bird is
flying, try changing the input to forward. If you think
that the bird is flapping its wings too quickly, you need to
change the input to the wait command.
For example, increase the input to wait and then click
OK.
forward 5 wait 2
Wait takes a number as input representing the number of
tenths of a second you want the computer to pause
between actions. Experiment with different numbers as
the input to wait.
Remember that the only turtle shape that turns is the
turtle shape itself. Otherwise, you need to design different
shapes to simulate shape turning.

2 TIP 1 CHANGING THE SHAPE OF A TURTLE


T I P

2
Will Murray
the Turtle
Please Step
Forward?

D
ID YOU EVER WONDER why one turtle is in front of
another ? Did you ever want the car to drive in front of
the tree and didn’t know how to get it to do so ?

WHEN

Well, the last turtle created in MicroWorlds is the one in


front. You can decide which turtle gets to be in front of
another. Perhaps you are designing a game of solitaire.
You would need a way for the user to click on a card and
bring it to the front. Sometimes your animations are just
better if one turtle moves in front of another.

DISCUSSION

You can do one of the following:


• Hold down the Shift key and simultaneously click on
the turtle you wish to move to the foreground.
• Right-click  Control-click on the turtle and choose In Front.
• Make sure that the turtle you want to move into the
front is current, and then type infront in the Command
Center.
It’s that easy!

W I L L M U R R AY THE TURTLE PLEASE STEP FORWARD? TIP 2 3


T I P

3
Cloning
a Turtle

S
OMETIMES YOU NEED MORE than one turtle to wear the
same costume, have the same heading and run the same
instruction. You can easily clone turtles to accomplish this.

WHEN

Whenever you need multiple turtles with the same shape,


size, heading, and instruction.

DISCUSSION

Follow these instructions:


1. Hatch a turtle, set its heading, and change its shape.
2. Right-click  Control-click
on the turtle and choose Edit to
give it an instruction.
3. Right-click  Control-click on the turtle and choose Copy.
4. Choose Paste from the Edit menu.
Click the Eye tool on the new turtle and notice that this
new turtle has the same DNA (state and instruction) as
its predecessor. Give it a new name if you wish.

4 TIP 3 CLONING A TURTLE


T I P

4
Graphics
Galore

A
NY FUNNY PICTURE of your favorite cartoon character
or beautiful photographic image that you can get into
your computer can be used as a turtle costume.

WHEN

If you want to put a picture of your friend’s head on a


turtle or use some cool clip-art as a “button,” then you
can import an image from a disk, scanner, the Internet, or
a digital camera and put it in a turtle shape.

DISCUSSION

Try the following ideas.

COPYING AND PASTING PICTURES INTO THE GRAPHIC TAB


AREA

Any picture in your computer’s clipboard may be pasted


into the shapes collection of the Graphics Tab area by
clicking on a shape and pasting the picture into that
shape. You may use the Selection tool to select any
graphics or stamped text on a page. Copy the selected area
and paste it into a shape in the shapes collection.

GRAPHICS GALORE TIP 4 5


USING TEXT AS A TURTLE SHAPE
1. Use the Stamper to stamp a transparent text box on the
screen.
2. Cut the original text by using Right-click  Control-click on it
and selecting Cut.
3. Select the stamped text with the Selection tool.
4. Choose Copy to copy that selection.
5. Select an empty shape in the shapes collection and
choose Paste to paste it into a shape.
Note: It is often difficult to click on a turtle wearing such
a costume because of the white space in the text. You can
stamp your text on a colored background if you want to
make your turtle easier to click on.

EXTENSIONS

DRAG AND DROP AN IMAGE FILE INTO A SHAPE


You can drag an image file from your Desktop and drop it
into a shape in your Graphics area. Drop it into an empty
shape so you don’t replace a shape that you need else-
where in your project!

CHANGING THE TURTLE’S COSTUME TO THE GRAPHICS


IT IS OVER

You may use the snapshape command to change the


turtle’s costume to a copy of the graphic area it happens
to be sitting on.
1. Position your turtle over the image you wish to snap.
2. Change the turtle’s shape to the shape you wish to
replace.
3. Type snapshape in the Command Center and your
turtle will be wearing a new costume! The shape in the
Graphics Tab area has been replaced.
See snapshape and snaparea in the Vocabulary for more
details.

6 TIP 4 GRAPHICS GALORE


T I P

5
Wordy
Pictures

W
ORDS CAN BE PART of your picture with a click
of the mouse !

WHEN

Whenever you need to label graphics such as maps or


diagrams, it’s best for the words to be stamped into the
background graphics. If you want to keep your text in the
same font and style on the Web or on another computer,
make it into a picture!

DISCUSSION
Text boxes are great for labeling screen graphics.
However, you may end up with many text boxes that can
be moved around if you do not freeze them.
If you wish to label a graphic and that label will not
change, consider stamping the text and removing the actual
text box. Here’s how:
1. Create a text box.
2. Type the label text. Be sure that the font, size, color,
and content is just what you want.
3. Right-click  Control-click on the text box and choose Trans-
parent.
4. Choose the Stamper tool to stamp the text on the screen.
5. Right-click  Control-click on the text and choose Cut to

remove the original text box.


The label is now part of the screen graphics and cannot be
edited.

WORDY PICTURES TIP 5 7


T I P

6
Special
Effects

A
RE YOU WONDERING how to jazz up your project ?
Do you like flashy special effects ?

WHEN

Adding special effects to your project gives it pizzazz! You


can flash text and turtles, and grow and shrink images to
grab people’s attention.

DISCUSSION

FLASHING THE TURTLE


1. Define this procedure:
to flash
ht
wait 2
st
wait 2
end
2. Type flash as the instruction in the turtle’s dialog box.
Set it to Many Times.
Click on the turtle!

8 TIP 6 SPECIAL EFFECTS


FLASHING THE TEXT
1. Define a flashtext procedure:
to flashtext
showtext
wait 2
hidetext
wait 2
end
2. Create a text box and write a message in it.
3. Create a button with flashtext as its instruction set to
Many Times.
Click on the flashtext button!

EXTENSIONS

Make the turtle enlarge when you click on it. Define an


enlarge procedure:
to enlarge
setsize 5
repeat 35 [setsize size + 1]
end
Set the turtle to the sun shape. Put enlarge in its dialog
box (set to Once). Click on the turtle!
Let’s add a sound to emphasize the effect. Import the
Grow sound from the Sounds folder. Edit the enlarge
procedure as follows:
to enlarge
setsize 5
launch [grow]
repeat 35 [setsize size + 1]
end

SPECIAL EFFECTS TIP 6


?? 9
T I P

7
Where
Should I
Click?

T
HERE ARE THREE DIFFERENT WAYS to click the mouse on
the MicroWorlds page and have procedures run.
Colors, buttons, and turtles may contain instructions
for what to do when a mouse is clicked on them. (Sounds,
melodies, music, and videos are clickable if visible, but do not
run procedures.)

WHEN

Interactive programs are increasingly dependent on the


user navigating and controlling the program via the mouse.
Any time the mouse button is clicked on a programmed
color, turtle, or button, a process will begin. Button and
turtle processes may also be stopped by clicking.

DISCUSSION

Buttons are a quick way of providing the user with a clear


manner of starting some action. They are deliberately
simple in appearance. If the look of a button does not
appeal to you, use a turtle or programmable color.
When should I use a programmable color, turtle, or button?
Use programmable colors when you don’t want to click
on a turtle or button or when a large area of the screen
can trigger one event. For example, clicking on the blue
sky will take the user to another page.

10 TIP 7 WHERE SHOULD I CLICK?


Use a button when you want to do something “quick and
dirty.” Buttons allow you to try something out quickly
without worrying about details. You may also want to
present the user with a text clue to click on. Verbs such as
Go, Start, and Play are the best instructions for buttons
since the entire instruction is visible on the button. If you
wish to use more than one or two commands in a button
instruction, you probably should consider combining the
instructions in a procedure and using the procedure name
as the button instruction.
Use a turtle when you want the user to click on a static
or animated icon. Arrows, signs, symbols, and other sorts
of icons often provide the look for turtles. You can also
copy text into turtle shapes to make a text button (see the
tip, Graphics Galore).

WHERE SHOULD I CLICK? TIP 7 11


T I P

8
Averting
Disaster

I
T DOESN’T TAKE MANY EXPERIENCES losing your work due
to a computer crash or programmer error before you learn
your lesson. Computers do strange things sometimes and
your latest programming idea can wreak havoc on hours worth
of work. Developing a few good habits and work strategies can
reduce the frequency of disaster.

WHEN

You should always be careful to protect your hard work.

DISCUSSION

There are several precautions you can take to preserve


your work and sanity.

SAVE EARLY AND OFTEN!


When you begin a project it is a good idea to save it right
away. This allows you to quickly save any changes you
make on an ongoing basis. Be sure to save every few
minutes and after every successful stroke of creative genius.
If you do something unexpected to your project, do the
following:
• Choose Open Project from the File menu.
• Do not save changes.
• Open the previously saved version.
• Continue working.

12 TIP 8 AV E R T I N G D I S A S T E R
USE FREEZEBG
Freezebg allows you to protect a background from
unwanted changes. This is handy when the user is
encouraged to draw or paint on a page, but you want to
return the background to its previous state for the next
user. After a freezebg command is issued, a page may be
returned to that state by using cg, clean, or double-clicking
on the Eraser.
Example:
• Paint a picture on the page.
• Type freezebg in the Command Center.
• Draw with the turtle or paint tools on the page.
• Double-click on the Eraser in the Graphics Tab area.
Voila! The background is a good as new!

EXTENSIONS

USE SNAPSHOT AND RESTORE


The snapshot command takes a snapshot of the current
page’s background. The next time a restore command is
used, the background will be restored to what it was at
the moment the snapshot was taken.
Example:
pd
fd 50 rt 90
snapshot
clean
restore

AV E R T I N G D I S A S T E R TIP 8 13
T I P

9
Don’t
Stop Me
Now!

O
CCASIONALLY YOU WISH to keep a user from clicking
off a button (or turtle) before all of its instructions
have been executed.

WHEN

Clicking on a button or turtle starts a process and clicking


a second time stops that process. In an interactive game or
a multimedia presentation, you may not want the user
clicking off a button before it is finished doing its job.

DISCUSSION

Freezing a button or turtle prevents it from being clicked


off. The instruction in the button or turtle must be set to
Once mode for this feature to work. Frozen buttons and
turtles are also unmovable.
Let’s say you have a text box that shows when you click
on a button and then disappears afterward. You don’t
want the user to click off the button in the middle of this
process because it will spoil your presentation.

14 TIP 9 DON’T STOP ME NOW!


To try this out:
1. Create a text box and type Welcome in it.
2. Write a procedure:
to welcome
showtext
wait 30
hidetext
end
3. Create a button with welcome as its instruction set to
Once. At the same time, check the name of the button:
it should be Button1 if this is the first on your page.
4. To freeze the button, in the Command Center type:
freeze "button1 If your button has another number,
change it.
Click on the welcome button. Try to click it off before
the text disappears.
To unfreeze the button, type:
unfreeze "button1

DON’T STOP ME NOW! TIP 9 15


T I P

10
Extra Pages
are Your
Friends

T
HERE IS NO SUBSTITUTE for good design and visual litera-
cy, but sometimes the creative process can get messy.
Some hints may help you keep your project on track.

WHEN

While building your project, it is a good idea to have a


Workshop page for messing about with graphics or for
storing objects that you will use later.

DISCUSSION

Create a new page in your project and name it Workshop.


You may use this page in a number of ways. Here are a
few suggestions:
• Import (or create) all of your video clips, turtles from
other projects, sliders, buttons, recorded sounds, and
melodies and leave them on this and other Workshop
pages. When you need the object in another part of the
project, cut and paste it to the appropriate page. Copy
and paste if you want to use the object in several different
pages.
• Test out a turtle graphics procedure on a page where
you won’t wreck your work if the procedure goes awry.
Once you are confident that the procedure works
properly, use it on the desired page.
• Paint, stamp, or import a graphic on the page, copy a
piece of the drawing and make it a shape by pasting it
in the shapes collection of the Graphics Tab area.

16 TIP 10 E X T R A PA G E S ARE YOUR FRIENDS


T I P

11
Going
Public
on the Web

D
o you want to share your creations with the world ?
You can publish your project on the World Wide Web
and view it on a Browser anywhere in the world !

WHEN

If you wish to publish your MicroWorlds project on the


Web, there are some tricks you need to know to enhance
performance (download time) and avoid bugs.

DISCUSSION

In order to view a MicroWorlds project on the Web, make


sure that the MicroWorlds Web Player is in your
Browser’s plug-in folder. If it isn’t, download it from our
Web site http://www.lcsi.ca/
Then you can simply use the Create HTML Template
item in the File menu to create a Web page containing
your MicroWorlds project. Double-click on the HTML file
that you have just created to view it locally in your
Browser.
Get some technical assistance from your Internet Service
Provider so you can upload both the Web page you just
created and the MicroWorlds project to a Web server.
Point your Browser to the new Web page to test it.

GOING PUBLIC ON THE WEB TIP 11 17


PLANNING FOR WEB PUBLISHING
There are some things you should consider while designing
a project that may run on the Web.

Use a smaller project size


Your MicroWorlds needs to fit within a Web Browser.
That means that the size of the project needs to be smaller
than the default size for a MicroWorlds project. You may
change the size of a project only before you begin working
on it.
To do so, choose New Project Size – Web Player from the
File Menu. This item automatically sets the project size
to 400 x 300.

There will be no Command Center and no Menus


Once a project is on the Web, you no longer have access to
the Command Center, Procedures Tab area, or menus.
This requires you to be sure your project is completed
before publishing it. You must also plan for new ways to
interact with the project since you can’t type commands
or access menus.
You can use one or more of the following strategies to add
interactive elements to your project.
• Use a startup procedure. Startup procedures always
run when the project opens. This means that your
project can begin automatically upon loading in the
Web page. Try using clickon in the startup procedure
to begin a procedure or animation.
• Use announce or screen text to explain what the user
should do. The announce instruction could be in a
startup procedure.
to startup
announce [Click on the little boy to begin]
end
• Use buttons and turtles to start the action.

18 TIP 11 GOING PUBLIC ON THE WEB


• Use question to request input from the user. For
example, let’s say you want the user to type fd
somenumber. You could write the following procedure
to request the information from the user.
to startup
question [How far should the turtle walk?]
fd answer
end

Command Check
The following commands are not available for use in
projects posted on the Web. Do not use these in your Web
project procedures or instructions:
cc merge importtext
newprojectsize printtext openworksheet
saveproject placepicture closeworksheet
setfooter loadpict setcell only
savepict loadshape getcell
saveshape loadtext
savetext exporttext

K.I.S.S. (Keep it Small Seymour)


Your MicroWorlds project will load quicker online if you
keep the file size as small as possible. If you must use
recorded sounds, keep them short. Otherwise, use MIDI
files or MicroWorlds melodies. Video clips should also be
avoided in your Web-based projects. This limitation is less
important on local networks and in institutions with
high-speed Internet access.

Numbers, numbers
If you happen to use any decimal numbers as text in your
project, create them as “executable” numbers instead. For
example, if you need to have the number 3.1 as text (not
stamped as graphics), then type it as 31 / 10 instead. This is
because decimal separators differ from country to country.

GOING PUBLIC ON THE WEB TIP 11 19


Pretty Text
Instead of using transparent text boxes, stamp the text
using the Stamp tool so that it becomes part of the graphics
of the page. This will avoid any conflict with the various
fonts that may or may not be present on the computers of
those viewing your project on the Web.

File names should be all one word and


in lowercase letters
Web servers and Browsers don’t care much for punctua-
tion and some are fussy about upper and lowercase
characters. Avoid confusion and use single-word file
names without spaces.

Tell folks about your site


Te l l L C S I i n f o @ l c s i . c a o r L o g o E xc h a n g e
logoexchange@stager.org about where fellow Logo enthu-
siasts may find your Web-based projects.

20 TIP 11 GOING PUBLIC ON THE WEB


T I P

12
Link Up
Your
Project

Y
OUR PROJECT LINKS are no longer limited to a computer.
You can make connections with the Web and your
friends on the Internet !

WHEN

You may have created a multimedia report where you


want folks to access a particular web site for more infor-
mation. You may want people reading your report to
e-mail you comments.

DISCUSSION

To create a hyperlink in your project, select the Hyperlink


Tool and click on the page. A dialog box appears.
• To link to a Web site, type the address in the space for a
URL. The address should start with http://. For example:
http://www.microworlds.com
• To send an e-mail message, it should start with mailto:
followed by the e-mail address. For example:
mailto: info@lcsi.ca
Give the hyperlink a name or leave the automatic name
(hyperlink1). Creating this hyperlink also adds a command
to MicroWorlds that accesses the link so you can put the
command in a button or turtle.
Now you can click on the hyperlink object on the page to
access your favorite web site or send e-mail to your friends!

LINK UP YOUR PROJECT TIP 12 21


T I P

13
What
Do Turtles
Own?

M
ICROWORLDS TURTLES can remember a number of
things. These are called state variables. This enhances
their intelligence and makes it easier to get turtles to
do tricky things without your needing to keep track of too many
variables.

WHEN

Whenever you want one or more turtles to remember


some information about its state or behavior, the turtle-
sown command will help you do so. Remembering a state
or behavior is one thing, but in MicroWorlds you will also
want a way of reporting that information to a procedure
or other turtle.

DISCUSSION

Turtles already own several state variables including


shape, color, heading, pos, xcor, ycor, and size. Each
one of these reporters has a corresponding one input com-
mand beginning with set. In other words, you may change
a state and report its value/condition.
Turtlesown is used to create other variables for every
turtle in a current project. Turtlesown takes a word as
input and that word is the name of the variable being cre-
ated.
turtlesown "initialpos

22 TIP 13 W H AT D O T U R T L E S O W N ?
Like built-in state variables, turtlesown creates a
reporter and a corresponding command beginning with
set.
There are three actions associated with turtlesown:
• Telling MicroWorlds to give a state variable to every
turtle in the project.
• Assigning a value to that state variable.
• Using that state variable in some way.
Let’s try an example.
1. Start a new project.
2. Hatch some turtles so that three turtles appear on the
page.
3. Change their shapes so that you can tell them apart:
t1, setsh "car
t2, setsh "plane
t3, setsh "boat
4. Tell MicroWorlds to give every turtle the state variable,
homepos:
turtlesown "homepos
5. Set the turtles to their “home” positions:
everyone [sethomepos pos]
6. Move the turtles to different parts of the page and then
set them back to their “homes”:
everyone [setpos homepos]
The best thing about turtlesown is that the state of each
variable is stored with the project upon saving. This
allows you to use these values at a later time.

W H AT D O T U R T L E S O W N ? TIP 13 23
T I P

14
All
Together
Now

Y
OU WOULD BE SURPRISED by how often you can give
every turtle on a page the same instruction. With a bit
of planning and problem solving, you can reduce your
programming workload by using the everyone command.

WHEN

Whenever you want every turtle on a page to do the same


thing, use everyone.

DISCUSSION

Everyone takes a list of instructions as a list and asks


every turtle on the current page to run those instructions.
Here are some examples of the use of everyone.
Causing every turtle to run its instruction:
everyone [clickon]
Hiding and showing every turtle:
everyone [st]
everyone [ht]
Setting the heading or position of each turtle:
everyone [seth 90]
everyone [setpos [-53 60]]

24 TIP 14 ALL TOGETHER NOW


Setting a value of a state variable created with turtlesown:
turtlesown "speed
t1, setspeed 1
t2, setspeed 5
t3, setspeed 10
everyone [forever [fd speed]]
Deleting every turtle:
everyone [remove who]

EXTENSIONS

Here is a clever way to make nearly everyone do some-


thing. You can ask MicroWorlds to check the state of a
particular turtle and decide whether or not that turtle
should then do something.
to nearly-everyone :condition :action
everyone [if (run :condition) :action]
end
Type the following in the Command Center:
nearly-everyone [color = 15] [setc 105]
The command above will look for any red turtles on the
page and change their color to blue.
What if you want most turtles to do something, but not
all? You could talkto or ask a list of turtles, or use a tool
procedure like everyone-but.
The everyone-but procedure has two inputs, the list of
turtles to exempt from the instruction and the instruction
all of the other turtles should run. The procedure then
looks through a list of turtles, one at a time, and checks to
see if that turtle is in the exception list. If it is, nothing
happens. If it isn’t, the instruction is run.

ALL TOGETHER NOW TIP 14 25


to everyone-but :exceptions :action
dolist [i turtles] [if not member? :i :exceptions [ask :i
[run :action]]]
end
to turtles
output get first pagelist "turtles
end
The turtles procedure reports the names of all the turtles
on the current page.
To test everyone-but:
1. Choose a new page.
2. Hatch five new turtles.
3. Type the following instructions:
everyone-but [t1 t3] [setc "blue]
everyone-but [t2] [rt 90]
everyone-but [t3] [remove who]

26 TIP 14 ALL TOGETHER NOW


T I P

15
Adding
Interactivity
to Your
Projects

Y
OU HAVE ALREADY LEARNED how turtles and buttons
may be used to add interactivity to a project. Sliders
and dialog boxes add other forms of interactivity to
MicroWorlds projects.

WHEN

Sliders are visual variables designed to report a numeric


value set by the user. They may also be used to display a
current value. The question and announce commands
add the common interface element of dialog boxes to
MicroWorlds. Announce is used to pop up on the screen
and deliver a text announcement. Question is used to
request information from a user.

DISCUSSION

SLIDERS
Try this:
1. Hatch a turtle.
2. Give it the instruction fd velocity – gravity set to
Many Times.
3. Create a slider by clicking on the Slider tool and then
on the page.
4. Name the slider velocity. Give it a range of 0 for
minimum and 99 for maximum.

ADDING INTERACTIVITY TO YOUR PROJECTS TIP 15 27


5. Create a second slider, name it gravity, and give it the
same range, 0 to 99.
6. Click on the turtle and adjust the velocity slider first
and then the gravity slider. What happens?
You are now using two sliders to visually control two
independent variables.

ANNOUNCE
Announce is used to display a pop-up dialog box containing
some text on the screen. It requires the user to click OK
before it disappears and allows the program to continue.
Therefore it really commands attention. Announce takes
one input of a word or list and displays that data on the
screen. Announce commonly precedes the sentence
reporter, which assembles words and lists into one input
to be displayed by announce.
Try the following:
announce [You win!]
announce 5 * 4
announce heading
announce heading * 5 * 4
announce (sentence who [wins the race!] "by 1 +
random 10 "lengths)

QUESTION
Question displays a dialog box, but this time asks the
user to input some sort of answer. The thing entered by
the user, even if nothing is entered and OK is pressed, is
stored in a special reporter called answer. Answer holds
that data until another question is asked or you quit
MicroWorlds. Sentence may prove helpful if variables
and literal text need to be combined in the question.

28 TIP 15 ADDING INTERACTIVITY TO YOUR PROJECTS


Try the following:
question [What is your name?]
show answer
question [What is today’s date?]
show (sentence [Today’s date is] answer)
question [Pick a number between 1 and 10]
fd answer * 10
question [What is your name, player?]
make "playername answer
Later on in your game, you can use this information to
communicate with the player. For example:
announce (sentence :playername [saved the galaxy!])

ADDING INTERACTIVITY TO YOUR PROJECTS TIP 15 29


T I P

16
Getting
Your
Messages
into Shape

D
ID YOU EVER WONDER if you could shape the messages
produced by the question and announce commands ?
This trick allows you to make the information appear in
the form you wish.

WHEN

Question and announce are used for interactive reports


and games. Usually, the message appears without any
format. This can make the message hard to read and less
effective. You can fix this by using a text box as the
container for the message.

DISCUSSION

Try the following:


1. Create a text box (Text1).
2. Write the following question in it, formatting it as you
wish:
What is the capital of Russia?
a. Paris
b. Moscow
c. St. Petersburg
Please answer with a letter.
3. Now type the following in the Command Center:
question text1
Look at the Question box: its format is exactly the same as
you typed it.

30 TIP 16 GETTING YOUR MESSAGES INTO SHAPE


T I P

17
Carefully
Building
a Simple
Calculator

T
HE FUN THING about text boxes is that while displaying
information, this data can also be automatically reported
in your program.

WHEN

Text boxes are nice alternatives to global variables and


using the question dialog box. You may enter specific
textual or numerical data in text boxes.

DISCUSSION

Try this example:


1. Choose a new page.
2. Create three text boxes named Length, Width, and
Area.
3. Type a number into both the Length and Width text
boxes. This exercise will not work unless there are numbers
in these two text boxes.
4. Create a button with setarea length * width as its
instruction. Leave the button set to Once.
5. Click the new button and watch the area being
calculated.

C A R E F U L LY B U I L D I N G A S I M P L E C A L C U L AT O R TIP 17 31
EXTENSIONS

Set the button running the instruction setarea length *


width to Many Times. This should make your program
calculate automatically.
Carefully change the numbers in the Length or Width text
box and watch the value for Area change automatically.
If you are concerned with keeping such implementations
from crashing, you may want to use the command, care-
fully, in the program to catch errors from crashing the
program.
Change the instruction on the button to read Calculate.
Write the following Calculate procedure on the Procedures
Tab area:
to Calculate
carefully [setarea length * width] [setarea "Error!]
end
Now the area text box will read, “Error!”, when a proper
number is not in the Length and Width text boxes.
Carefully tries to run the first list of instructions and if
an error is created, runs the second list of instructions. It
is very handy for trapping user errors.

32 TIP 17 C A R E F U L LY B U I L D I N G A S I M P L E C A L C U L AT O R
T I P

18
Follow
the Yellow
Brick Road

S
OMETIMES YOU NEED A TURTLE to follow an irregular
path. You could use brute force to tell the turtle how to
move precisely by programming an endless series of fd,
bk, rt, and It commands. Or...

WHEN

Instead of the inefficient brute force strategy, you can


drop turtle “bread crumbs” along the path and ask a turtle
to follow them.

DISCUSSION

Turtles know where they are and which way they are
facing. Pos and heading are reporters assigned to turtles.
The command, towards, turns the current turtle towards
a specified turtle. Distance is a reporter that tells us the
distance between one turtle and another.
t1, towards "t2
tells the turtle, t1, to face t2.
t1, show distance "t2
shows the number of turtle steps between t1 and t2.
Say you want your turtle to run around an irregular track.
A clever way of controlling the turtle’s motion is to
“drop” a series of other turtles strategically around the
track. You may then use towards and distance to follow
the path.

FOLLOW THE YELLOW BRICK ROAD TIP 18 33


Follow these steps:
1. Name a turtle Racer.
2. Hatch new turtles and drop them strategically along the
path in the order in which you create them.
3. Type the following instructions in the Command Center:
everyone [ht]
racer, st
Be sure to remember the names of the turtles you
dropped along the path.
4. Write the following procedure on the Procedures Tab
area:
to follow
racer,
towards "t1
fd distance "t1
towards "t2
fd distance "t2
towards "t3
fd distance "t3
towards "t4
fd distance "t4
end
Here is another smoother follow procedure:
Follow2 uses the glide command rather than forward to
move the turtle. You should notice more fluid movement
in the turtle. Glide takes two inputs, the distance you
wish to travel and the rate at which you will glide there.
Try it for yourself.
to follow2
racer,
towards "t1
glide distance "t1 2
towards "t2
glide distance "t2 2
towards "t3
glide distance "t3 2
towards "t4
glide distance "t4 2
end
34 TIP 18 FOLLOW THE YELLOW BRICK ROAD
When there are more than a few “buoys” set up along yourEXTENSIONS
path, you may wish to write a more efficient procedure
using the dolist command. Dolist runs the instruction
list for each item in a list. The first input is a list contain-
ing a temporary variable name and a list of items. The
second input is a list of instructions that uses the variable
name included in the first input. Followthepath is
written elegantly to take advantage of dolist. The racer
turtle will travel to each of the “buoys” in succession. The
pointlist procedure is a reporter designed to reduce the
number of times you have to type the list of turtle names
and really cleans up the look of the procedures.
to followthepath
dolist [i pointlist] [towards :i fd distance :i]
end
to pointlist
output [t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14
t15 t16]
end
If you wish to control the speed of the chase, you may
replace the fd in followthepath with the glide command.
Glide takes two inputs, the distance you wish to travel
and the number of steps it will glide at a time, thereby
controlling the speed of the glide.
to followthepath2
dolist [i pointlist] [towards :i glide distance :i 1]
end
The turtle will now glide by one step at a time in
followthepath2.

FOLLOW THE YELLOW BRICK ROAD TIP 18 35


T I P

19
When
Turtles
Collide

I
N SOME SITUATIONS, you can program a color to cause an
action when a turtle hits that color. This works fine for hitting
standing targets, but sometimes you want to know if a
turtle actually collides with another turtle. MicroWorlds uses
the touching ? reporter to check for such collisions.

WHEN

Most video games require that you know when one moving
object collides with another. Science simulations may also
use collision detection.

DISCUSSION

Follow these steps:


1. Hatch two turtles.
2. Name the first turtle, Car, and the second turtle,
Pedestrian.
3. Program the turtle named Car to have the following
instruction set to Many Times:
fd 2
4. Write a procedure to make the pedestrian move away
when it gets “hit” by the car:
to hit
fd 2
if touching? "car "pedestrian [ht wait 20 fd 100 rt
random 360 st]
end
36 TIP 19 WHEN TURTLES COLLIDE
5. Make hit the pedestrian-turtle’s instruction, set to
Many Times:
6. Set the car-turtle’s shape to a car.
car, setsh "car
7. Set the other turtle’s shape to a human shape.
pedestrian, setsh "runner2
Type in the Command Center:
everyone [rt random 360 clickon]
The pedestrian is now programmed to detect being hit by
the car. When the car hits the pedestrian, the turtle will
temporarily disappear and reappear 100 steps away with a
new random heading.

EXTENSIONS

What if you have many pedestrians, and you want your


program to detect each one that is hit? Try this:
1. Copy the pedestrian turtle and paste a few copies on
the screen.
2. Edit the hit program:
to hit
fd 2
if touching? "car who [ht wait 20 fd 100 rt random 360 st]
end
3. Now type:
everyone [rt random 360 clickon]
Who reports the current turtle. Now any of the pedestrians
can detect whether it is hit by a car!

WHEN TURTLES COLLIDE TIP 19 37


T I P

20
Turn
Your Pages

M
OST SOFTWARE APPLICATIONS with multiple screens
have a way of navigating between screens by clicking
on buttons. Often these buttons have arrows as icons
indicating previous or next screen.

WHEN

If you need navigational buttons, they are easy to create in


MicroWorlds. These buttons can either be actual buttons
with the words previous and next as their instruction or
turtles with shapes of your choosing containing the same
instructions.

DISCUSSION

The commands, previous and next, are not primitives in


MicroWorlds. Therefore you need to write them as proce-
dures on the Procedures Tab area.
In order to know which page you just left or which page
is just around the corner, you need to know the name of
the page you are on. The expression, first pagelist, will
report the name of your current page. These reporters
will be used in the next and previous procedures.
The procedures for these two new commands are quite
simple and tedious if a project has many pages.

38 TIP 20 T U R N Y O U R PA G E S
For example:
to previous
if (first pagelist) = "page2 [page1 stop]
if (first pagelist) = "page3 [page2]
end
to next
if (first pagelist) = "page1 [page2 stop]
if (first pagelist) = "page2 [page3]
end
The procedures in the square brackets are the names of
the pages you wish to turn to. Note the use of stop in the
first line of each procedure. This stops the procedure from
continuing provided that the if statement is true.
Otherwise, clicking the next button on Page1 may turn to
Page3.

T U R N Y O U R PA G E S TIP 20 39
T I P

21
Changing
Your Mind

B
UTTONS CAN BE LIKE CHAMELEONS, changing their
instructions magically via Logo programming.

WHEN

Let’s say that you want a button to hide or show some


text. It would be great if the button could feature the
instruction that will change the state of the text box. In
other words, invisible will hide the text and visible will
show it.

DISCUSSION

In order to do this, you need to know the name of the but-


ton. The button’s name is always some form of button1,
button2, etc..., and has nothing to do with its instruction!
Right-click  Control-click on a button and choose Edit to check

its name. You can also find the button’s name by clicking
the Eye tool on it.
Next, you need to decide if the button’s action should
launch Once or run forever (Many Times). The commands,
launch and forever, are necessary in programming a
button’s instruction.
Get is a primitive that reports the state of screen objects.
Set is a command that can change the different states. See
the online help for more detailed information about get
and set.

40 TIP 21 CHANGING YOUR MIND


Try this:
• Create a button with the instruction, Nothing, and
then type this in the Command Center:
show get "button1 "rule
• Type the following in the Command Center and watch
what happens...
set "button1 "rule [launch [yippee!]]
Now, let’s program the invisible/visible button.
to invisible
hidetext
set "button1 "rule [launch [visible]]
end
to visible
showtext
set "button1 "rule [launch [invisible]]
end
Create a text box and type something in it. Set the but-
ton’s instruction to invisible. Then click on it and see
what happens. Click again to test the chameleon-like
button!

CHANGING YOUR MIND TIP 21 41


T I P

22
Text Box
Magic

T
HE WORDS IN A TEXT BOX can make things happen !
Using the “magic” command onreadline, your text box
can act like the Command Center.

WHEN

Since you don’t have a Command Center when you view


your project on the Web, you may want to use a text box
to fulfill this function. This feature also makes classic
word and list projects better for presentations. Your text
input and output all takes place in a text box!

DISCUSSION

Create a text box named Text1. To make your text box act
like a Command Center, type (in the Command Center):
onreadline "text1 "run
The first input is the name of the text box and the second
input is the instruction to run. In this case, run runs its
input as a Logo instruction. Hatch a turtle, then try
typing a command such as forward 50 in the text box
now. It moves the turtle forward!
To turn off this feature, make the second input to
onreadline empty.
onreadline "text1 "

42 TIP 22 TEXT BOX MAGIC


EXTENSIONS

Make your text box reverse words! Type these procedures


in the Procedures Tab area:
to reverse :word
pr revword :word
end
to revword :word
if :word = " [output " ]
op word last :word revword butlast :word
end
Create a text box called Text1, then type this in the
Command Center:
onreadline "text1 "reverse
Type a word into the text box and watch it reverse!

TEXT BOX MAGIC TIP 22 43

Vous aimerez peut-être aussi