Today's lesson is about methods. A method tells the computer HOW to do something. For example, here is a method for eating:
== Eat Lunch ==
Select food
Pay for food
Select a seat
Sit down
Pick up knife and fork
** repeat **
Cut food
Place one portion in your mouth
Chew repeatedly (at least 20 times)
Swallow
** until food is all gone **
In Alice, you will be writing methods that tell objects
how to move.
The ice-skater in Tutorial #1 has a method that tells how to do a
Simple Spin, similar to this:
Do together means two movements happen simultaneously - she raises her arms and stretches one leg.
Loop means that something is repeated several times - in this case, a half turn is repeated 5 times.
.....
At the end, she strikes another "pose".
Each World has a story-line with a list of
actions that will happen. This is similar to a story-board
for a video editor (like Movie Maker).
For today's Tutorial #2 (about the rabbit and the cell phone), the
world's story-line looks like this:
Each command is the name of a method. Each
method contains a list of commands. "Say" makes a message pop up on the screen. |
|
The "Cellphone.ring" method refers to another set of commands. Inside the .ring method it looks like this:
Each command can be "opened up" to show the details of
the method (e.g. a list of commands).
Even a very simple animation like the bunny consists of hundreds
or thousands of commands.
We use methods for two reasons: