Professional Documents
Culture Documents
You need to have downloaded and installed Cocoa before taking this tutorial.
Table of Contents
Write a "Move Right" Rule Get help with the tutorial setup
Maintained by the Apple Cocoa DR Team. Last updated Fri, June 20 1997.
E-mail cocoa@apple.com with problems or questions.
basicforPDF.html Page 1
Please open your copy of Cocoa and follow along with the steps described in the tutorial.
Some words on these pages are linked to the Tutorial Word List: click on a word if you'd like to see a
definition of it. Click on the BACK button in your browser to return to the Tutorial.
ABOUT COCOA
In Cocoa, only pieces on the board can act in a world. You show your pieces how to act by writing
rules of behavior. All pieces which have rules and are on the board get a chance to try their rules on
every clock tick.
This tutorial will show you how to build an obstacle course for a piece to move around.
You'll make a piece and give it a rule that moves it to the right. You'll then give it rules for jumping
on and off of obstacles that get in its way.
And, if you want to see what else your piece can do, you can build a world with more obstacles in it
and give your piece more ways to get through it.
You can download the "Starter World" to your computer. It's about 8K and will take less than a
minute to download.
When you open Cocoa, click the "Open Saved World" button.
Then open the "Starter World" to follow along with this tutorial.
In Cocoa, you start by creating a piece and giving it an appearance. Try not to spend too much time
drawing. You can use a picture that has been drawn in another program or one from the Scrapbook.
Click anywhere above the ground pieces to create new piece on the board.
What a piece looks like is called its appearance. You can change a piece's appearance with the paint
tool.
This opens the Appearance Editor where you can draw an appearance.
You can draw any appearance you like, or paste in any picture copied from another program into the
Appearance editor. Use an appearance that takes up only one square on the Cocoa grid.
4. Use the painting tools to draw the appearance or paste one in that you copied from
another program.
You're done with the appearance. Click the.. ..appearance done button.
The second step is to write a rule that shows your piece what to do. You want your pieces to act a
certain way when they are in a certain situation. To get through the obstacle course, the first thing
your piece has to know how to do is move to the right. You show it how to do that by writing a rule.
Here, we want to set up this situation: If there's an empty space to the right of your piece, it will
move right.
This opens the Rule editor. It shows the before and after sides of a rule.
The board is dark and you can see the grid in the background. A spotlight lights up the area around
your piece.
Before you do anything, the before and after sides in the Rule Editor are the same as what's in the
spotlight on the board.
When you're writing a rule and you do something with your piece, those actions get recorded as a
rule. You can show your piece what to do either in the spotlight on the board or the after side of
the Rule Editor.
Before a rule will work, the left side of the Rule Editor must match what's on the board. It's called
the BEFORE SIDE of the rule. When a rule works, the actions that were recorded when you wrote
the rule get done. Those recorded actions are shown on the right side of the Rule Editor. It's called
the AFTER SIDE of the rule.
In this rule, the piece moves to the right if the space is empty. The action is shown both on the board
and on the after side of the Rule Editor. Notice that the spotlight shows only 2 spaces. That's all your
piece needs to know: as long as there's 1 empty space next to it, it will keep on moving right.
2. Drag the spotlight handles to include ONE empty space to the right.
This shows your piece the area you're interested in. It only sees what's in the spotlight and will
ignore everything outside the spotlight.
To show that you want your piece to move to the right, move it into the space to the right. Put the
mouse over the piece, click down on the mouse button and drag.
You're done with this rule. Click the.. ..rule done button.
You can now see the rule run. Press on.. ..to run the clock and..
Your piece will keep moving right as long as nothing gets in its way. Now you can put
in some obstacles for your piece to jump around.
To build a world, you break up the actions into small steps and you write rules for the pieces to
perform the small steps. In the obstacle course world, you create obstacles and you write rules that
will tell your piece to jump ON and OFF an obstacle. It takes 2 small jumps rather than one big leap
over an obstacle.
LOOK BEFORE YOU LEAP! Your pieces only know what you tell them to do. You want your
pieces to act a certain way when they are in a certain situation.
Sometimes you have to try one way before you realize you might want your pieces to act differently.
Don't be afraid to write a rule and see what it does. If you don't like it you can delete it and write a
new rule.
After you write rules that tell your piece when to jump, you can set up an obstacle course for your
piece to jump around.
But first, you need to make a second piece to be the obstacles in this world.
Click to the right of your piece to create a new piece on the board.
What a piece looks like is called its appearance. You can change a piece's appearance with the paint
tool.
This opens the Appearance Editor where you can draw an appearance.
3. Use the painting tools to draw the appearance or paste one in that you copied from
another program.
You're done with the appearance. Click the.. ..appearance Done button.
Your piece knows how to move right, but put an obstacle in its way and it can't move anymore. Start
the clock to see. Stop the clock when your piece gets stuck next to the obstacle.
Here, we want to set up this situation: if there's a block to the right of your piece and the space above
is empty, then your piece will JUMP ON the block. This is the first step to getting around obstacles.
For this rule, move the block to the right side of your piece and make certain the space above it is
empty.
2. Drag the spotlight handles to include the block in the space to the right and the empty
The board has a grid pattern and you can only move pieces into spaces marked by the squares of the
grid.
If there's a block to the right of me and the space above is empty . . . then jump on
the block.
You're done with this rule. Click the.. ..rule done button.
Remember, you break up the actions into small steps. The next step is to write a rule that will get
your piece down off of the block.
Now you will write a rule for you piece to jump down. Here's the situation: if your piece is on top of
a block and the space to the right of the block is empty, then your piece will jump down off of the
block into that space.
For this rule, your piece is already in the position you want, so you can go ahead and write the rule.
2. Drag the spotlight handles to include the block below your piece and the empty space
to the right.
If I'm on top of a block and the space to the right of the block is empty . . . then
jump down off of the block.
You're done with this rule. Click the.. ..rule done button.
You can now see the rule run. Press on.. ..to run the clock and..
Your piece will move right until it reaches the block. It will jump on and off the block and then
continue to move right.
Now you can put more blocks on the board and see if your piece can make it through the obstacle
course you build.
Anytime you want to name your types of pieces or get more pieces of any type, go to the PIECE
menu and select "Show Types."
In this world, your piece can move around in different ways. Set up the board like the example
shown here to see how your piece can use these 3 rules - move right, jump on and jump down - to
move through these different obstacles.
What's the largest number of obstacles your piece can move around without going off the right side
of the screen?
You can download the "Obstacle Course" world to your computer. It's about 15K and will
take less than 1 minute to download with a 14.4 speed modem.
It has the rules already written for the Cocoa mascot. You can open it and start the clock to see the the
Add new obstacles and rules to your piece to make it run through a different obstacle course:
You can download the "More Obstacles" world to your computer. It's 20K and will take
about 1 minute to download with a 14.4 speed modem.
You'll see that by adding some rules your piece can get around almost any obstacle you build with the
blocks.
Try some of your own experiments by adding different obstacles and giving rules for your piece to
do more.
After you've seen one, you can come back and choose a different one.
If you'd rather skip the tutorial, you can get these worlds now. See below.
You can download the "Beyond Basics" worlds to your computer. It's 95K and will take
about 2 minutes to download with a 14.4 speed modem. You will get a folder with all the worlds
ready for you to see.
Each world has the rules already written for the Cocoa mascot. You can open one and start the clock
to see the mascot run through the obstacle course.
Start a new world by copying the "Obstacle Course" world done in the "Basics" section. If you
skipped that section, download the "Obstacle Course" world and start with it to go on with
this section.
To avoid confusion, rename the new world "Turning Around" before opening it.
CHANGE MY APPEARANCE
Your piece already knows how to move right when it has a certain appearance and when its in a
certain situation. Appearances are important. If the appearance changes, the situation changes and
your piece will need new rules for the new situation.
In this world, you will write a rule for your piece to turn around if there are 2 blocks in its way.
This will give your piece more ways to get around the obstacle course.
First, you'll need to make a second appearance that your piece will have when it's moving left.
Then you'll write the rule that tells your piece when to change its appearance.
1. Select your piece on the board (it looks dark), go to the APPEARANCE menu and
This opens the Appearances window. Any time you want to see all the appearances a piece has, just
go to the APPEARANCE menu and select "Show Appearances."
This opens the Appearance Editor for your piece with a COPY of the first appearance it had. You can
change this new appearance so that your piece faces to the left.
In this example, the appearance will be flipped so that the Cocoa mascot is facing left.
You're done with the appearance. Click the.. ..appearance done button.
Your piece has 2 appearances: appearance 1 faces right and appearance 2 faces left.
Now that your piece has 2 appearances, you can write the rule that will change your piece's
appearance.
You want your pieces to act a certain way when they are in a certain situation. Appearances are
important. Your piece has rules for when its appearance is facing right, but we want to change that. If
the appearance changes, the situation changes and your piece will need new rules for the new
situation.
Here, we want to set up this situation: if your piece is moving to the right, but there are 2 blocks in its
way, it turns around to the left.
For this rule, put 2 blocks, one above the other, in the space to the right of your piece. Your piece
should still be facing right. (If your piece is facing left, go to the APPEARANCE menu and select
"appearance 1" at the bottom of the menu.)
This opens the Rule Editor where you write the rule.
3. Drag appearance 2 (facing left) onto the piece. It has to go on the AFTER side of the
Rule Editor.
This says that you want to change the appearance from facing right to facing left.
If I'm moving right and there are 2 blocks, one above the other, to the right of me .
. . then I'll turn to the left.
You're done with this rule. Click the.. ..rule done button.
If you dragged the Cocoa mascot's "appearance 2" onto the Block in the rule, the Block wouldn't
change its appearance to look like the Cocoa mascot. When you're changing appearances, be careful
to check who's Appearances you're using and which piece you're dragging that appearance onto.
Now that your piece has turned to the left, it doesn't know what to do next. If you run the world, it
will not move. Appearance is important, so now you need to tell it what to do next.
The easiest thing to do is give it a rule that tells it to move left when its facing left. If you need help,
go back to the Move Right section to see how that rule was done, but, this time, write a rule to
move the piece left.
The next thing your piece might do is jump on then off the block when it's moving left. If you need
help, go back to the Jump section, to see how that was done.
You can download the "Turning Around" world to your computer to see what the finished
world looks like. It's about 28K and will take about 1 minute to download with a 14.4 speed modem.
This world has the rules already written for the Cocoa mascot. You can open it and run the world.
Start a new world by copying the "Obstacle Course" world done in the "Basics" section. If you
skipped that section, download the "Obstacle Course" world and start with it to go on with
this section.
To avoid confusion, rename the new world "Eating Food" before opening it.
Your piece already knows how to move right and jump over a block. That takes a lot of energy!
In this new world, your piece will delete the other piece: this is the kind of rule you write when you
want one piece to "eat" the other piece to get energy.
First, you'll need to make a second piece that your piece would like to eat.
Click to the right of your piece to place the new piece on the board.
What a piece looks like is called its appearance. You can change a piece's appearance with the paint
tool.
This opens the Appearance Editor where you can draw an appearance.
You can draw any appearance you like, or paste in any picture you draw in a painting program, then
copy and paste it in as an appearance. Here, use an appearance that takes up only one square on the
grid.
3. Click on the painting tools to draw the appearance or paste one in.
You're done with the appearance. Click the.. ..appearance done button.
You want your pieces to act a certain way when they are in a certain situation. To do this, you set up
the pieces on the board BEFORE you write the rules which tell them how to act. If your pieces are
not in the position that you want, move the pieces into position before you write the rule.
Here, we want to set up this situation: if there's food in the space to the right of your piece, it will eat
it and move right.
For this rule, move the "food" to the right of your piece.
2. Drag the spotlight handles to include the food piece on the right.
Now we can see what your piece wants to eat. To delete a piece out of the world, you use the delete
tool.
If there is food in the space to the right of me . . . then "eat" it and move to the
right.
You're done with this rule. Click the.. ..rule done button.
Now you can put out more food for your piece to eat.
If you want, you can name the type "Food" in the Types window.
Anytime you want more pieces of any type, go to the PIECE menu and select "Show Types." Then,
you can drag out any piece you want onto the board.
Set up food all around the obstacle course, wherever your piece can run into the "food" on its right.
Soon your piece will eat up all the food you've put out.
Try writing rules for your piece to eat food placed around the blocks.
You can download the "Eating Food" world to your computer to see what the finished world
looks like. It's 23K and will take about 1 minute to download with a 14.4 speed modem.
This world has the rules already written for the Cocoa mascot. You can open it and start the world.
Start a new world by copying the "Obstacle Course" world done in the "Basics" section. If you
skipped that section, download the "Obstacle Course" world and start with it to go on with
this section.
To avoid confusion, rename the new world "Moving Obstacles" before opening it.
Your piece already knows how to move right and jump on and off a block. How about giving your
piece some rules to change the obstacle course? As it moves around the board, it can move
obstacles and then get around them.
In this new world, your piece will be able to move a block if there are 2 stacked, one above the other,
on its right and if there's an empty space to the left.
You want your pieces to act a certain way when they are in a certain situation. You can change the
situation by moving obstacles, or you can give rules to your piece to move obstacles while it moves
through the obstacle course.
Here, we want to set up this situation: if there are 2 blocks one above the other to the right of your
piece, it will move 1 block to the empty space to its left, if the space is empty.
For this rule, move your piece where there is empty space to the left and to the right. In the space to
the right of your piece, stack 2 blocks, one above the other.
This opens the Rule Editor where you write the rule.
2. Drag the spotlight handles to include both blocks in the space to the right of your
3. Move the top block to the empty space to the left of your piece.
If there are 2 blocks, one above the other, to the right of me, move the top block to
the space to my left, only if that space is empty.
You're done with this rule. Click the.. ..rule done button.
What if the space to the left of your piece is not empty? Then, your piece could not move one of the
Mon, Jun 23, 1997 12:11 PM
beyondforPDF.html Page 15
blocks.
Write some other rules that will let your piece move one of the blocks to a different empty spaces, for
instance, on the right side of the block or down below the block.
You can download the "Moving Obstacles" world to your computer to see what the finished
world looks like. It's 23K and will take about 1 minute to download with a 14.4 speed modem.
This world has the rules already written for the Cocoa mascot. You can open it and start the world.
Start a new world by copying the "Obstacle Course" world done in the "Basics" section. If you
skipped that section, download the "Obstacle Course" world and start with it to go on with
this section.
To avoid confusion, rename the new world "Creating Obstacles" before opening it.
Your piece already knows how to move right and jump on and off a block. How about giving your
piece some rules to build the obstacle course itself? As it moves around the board, it can create new
obstacles and then it will have to get around them.
You want your pieces to act a certain way when they are in a certain situation. You can change the
situation by adding obstacles, or you can give rules to your piece to add obstacles while it moves
through the obstacle course.
Here, we want to set up this situation: if there are 2 blocks, one above the other, to the right of your
piece, it will move up and another block will appear.
For this rule, move 2 blocks, one above the other, to the right of your piece.
This opens the Rule Editor where you write the rule.
2. Drag the spotlight handles to include the 2 blocks to the right of your piece.
To create another block in the rule, you need to see all the types for this world and make a copy of the
block.
5. Drag a copy of the block from "Types" window to the AFTER side of the rule.
Anytime you want more pieces of any type, go to the PIECE menu and select "Show Types" then
drag out any piece you want onto the board.
If there are 2 blocks, one above the other, to the right of me . . . I'll move up and
another block will appear under me.
You're done with this rule. Click the.. ..rule done button.
Write other rules that will let your piece move in other directions and make obstacles appear in the
empty spaces. But be careful, if you write too many rules that create obstacles, there will soon be no
space to move around!
You can download the "Creating Obstacles" world to your computer to see what the finished
world looks like. It's about 20K and will take about 1 minute to download with a 14.4 speed modem.
This world has the rules already written for the Cocoa mascot. You can open it and start the world.
Start a new world by copying the "Obstacle Course" world done in the "Basics" section. If you
skipped that section, download the "Obstacle Course" world and start with it to go on with
this section.
To avoid confusion, rename the new world "Making Sound" before opening it.
MAKING A SOUND
Your piece already knows how to move around the obstacle course, but for fun you could have it
make sound as it moves around. This is a good way to attract attention to something different
happening in the world.
In this world, you will write a rule for your piece to make a sound if there are 2 blocks in its way
and it can't get around it.
First, you'll need to record a sound. Then you will write the rule that tells your piece to say the sound
when it gets stuck next to 2 blocks.
RECORD A SOUND
1. Select your piece on the board (it looks dark), go to the SOUND menu and select
"Show Sounds."
This opens the Sounds window. Any time you want to see all the sounds a piece has to say, just go
to the SOUND menu and select "Show Sounds."
This opens the Sound Editor for your piece with Record, Stop and Play buttons.
There should be "waves" coming from the speaker icon.. ..when you make a sound
into the microphone. You may want to practice the sound before you record it.
You can click on the.. ..button if you don't like the sound, and then record a new
one.
You'll have to go back to the SOUND menu and select "New Sound" to start recording again. When
The new sound appears in the Sounds window. To avoid confusion later, you can name it "Uh Oh."
Now that your piece has a sound to say, you can write the rule that lets your piece say the sound
when the world runs.
You want your pieces to say a certain sound when they are in a certain situation. Sounds make your
world more fun and can be good way to show that something different is happening in the world.
Here, we want to set up this situation: if your piece is moving to the right, but there are at least 2
blocks in its way, it says "Uh Oh".
For this rule, put 2 blocks, one above the other, in the space to the right of your piece.
This opens the Rule Editor where you write the rule.
Now you show that you want a sound to be said by your piece when the rule runs.
3. Drag the "Uh Oh" sound onto the piece. It has to go on the AFTER side of the Rule
Editor.
This says that you want your piece to say "Uh Oh".
If I'm moving right and there are 2 blocks, one above the other, to the right of me .
. . then I'll say "Uh Oh".
You're done with this rule. Click the.. ..rule Done button.
If you dragged the Cocoa mascot's "Uh Oh" sound onto the Block in the rule, the Block wouldn't
say "Uh Oh." When you're making sounds, be careful to check whose Sounds you're using and
which piece you're dragging that sound onto.
Now that your piece says something in one situation, you can record other sounds to have it say other
things in other situations. If you add another of the same piece into the world, you can have them
meet and say "Hello" or "Goodbye".
You can download the "Making Sound" world to your computer to see what the finished
world looks like. It's 43K and will take about 1 minute to download with a 14.4 speed modem.
This world has the rules already written for the Cocoa mascot. You can open it and start the world.
If you've built the worlds described in the Beyond the Basics section, you've written many
different rules, some for the same situation: when there are 2 blocks, one above the other to the right
of your piece. All rules are checked from the top to the bottom of the rule list. But, you may not
always want your piece act that way.
You can change the way rules are checked to change your piece's behavior.
You can put some rules together in a Rule Set to give your piece different behavior.
The cursor becomes a Rule Set tool. Click in any white space between the rules.
This creates an empty box that you can put rules into and change the way your piece acts.
Now, you can drag rules into the rule set, for instance:
Move a Block
Create a Block
Close the rule set by clicking on the triangle next to the rule set name.
The rules are kept together and separate from the other rules in the rule list.
Notice that there are rules below the rule set. Because the rules are checked from the top to the bottom
of the rule list, the rules below the rule set will only be checked if none of the rules inside the rule set
work or if you choose a different rule set type.
Choose one rule set option and run the world to see how the piece acts differently, depending on
which rule set option you choose.
Do First Match finds the FIRST rule in the rule set that works, it performs the actions and then
another piece gets a turn.
When to use this: Keep rules together if you want one set of rules to be checked in the order that
they are listed, but separately from all other rules in the rule list outside the set. For instance, put all
of your piece's "Move" rules in a Do First Match rule set. If you want it to move right every time that
it can, move the "Move Right" rule to the top of the set.
Randomize and Do First: the order of the rules in the rule set CHANGES each time the piece
gets a turn. It finds the first rule that works, it performs the actions and then another piece gets a turn.
When to use this: Sometimes you want your piece to act in an unpredictable way. For instance, if
you put all of your piece's "Move" rules in a Randomize & Do First rule set, it will move in different
directions rather than the same direction on every clock tick.
Do all and Continue: the rule order stays the same, but it finds ALL the rules in the Rule Set that
work, it performs ALL the actions in those rules that it can and then it GOES ON to check the rules
that are below the Do All & Continue rule set to see if they work.
When to use this: Best used to keep track of or change variables leaving other rules outside a Do
All & Continue rule set. For instance, you can "Add 1 to Age" so that your piece will get older, and it
will GO ON to check if it can do something else on the same clock tick.
You can download the "Grouping Rules" world to your computer. It's about 28K and will
take about 1 minute to download with a 14.4 speed modem.
Type in the name you'd like to use for your world or this version of your world.
Saving Worlds this way allows you to open them in Cocoa and change how they work later. The
other two formats don't let you do this.
After you fill in the information, you can "Save for Internet"
A ".cco" media file and a ".html" web page file will be created. The web page can be opened with a
web browser and the world will be viewed inside the web page.
Build Autoplayer
Type in the name you'd like to use for this AutoPlayer of your world
Word List
World
In a world, pieces can act in certain ways only when in a certain situation. Pieces don't act the same way all
the time. How they act depends on the situation you create in the world. You write rules to control how
pieces act in the world.
Board
The Board is the area where the pieces act. The pieces can only act in the order which they were put out on
the board.
Piece
Anything that can appear on the board, whether it has rules or not, is a piece. When you create a piece,
you're actually creating a "Type" of piece, and the piece on the board is a copy of that Type of piece. You can
have many pieces of the same Type, all acting on the Board at once. You can move, create, delete, copy, and
name a Type and a Piece.
Rule
A rule is a "plan": it has a "Before" situation to check (the left side of the Rule) and an "After" situation with
actions to do (the right side of the Rule). All the rules for a piece are listed in the Rules window. The rules
are in the order that will be checked for the piece to act. You can create, delete, name, and reorder a rule.
Clock Tick
In one clock tick, every piece gets a chance to test its rules and do what it can. A clock tick can run either
forward so all pieces can try to do something or it can run backward so all pieces UNDO everything they did
on the last clock tick.
Appearance
What the piece looks like. You can draw an appearance in Cocoa or paste one in that you drew and copied
from a drawing program. Pieces can have many different appearances.
Grid
The Board is separated into a grid of squares like a checkerboard. When you draw an appearance or write a
rule, you can see the grid lines in the background. When pieces move around in a world, they can only move
from square to square on the grid.
Painting Tools
A set of tools for drawing your piece's appearance; for example, pencil, paintbrush, and eraser. There is a
PAINT menu that gives you choices for flipping and rotating the part of the drawing you've selected.
Spotlight (Handles)
The Spotlight lights up the area around your piece when you're writing a rule for it. You drag the handles out
to show more of the board and to include pieces that should be in the rule. Your piece sees what's in the
spotlight and it ignores anything outside the spotlight.
Variable
Information about pieces such as their appearance or what they said. Pieces can track different variables and
the variables can keep different kinds of information. You can create, delete, move, and name a variable.
Delete tool
The delete tool is used to delete anything that you want to delete out of your world, for example, pieces or
rules.
Sound
What the piece can say. You can record new sounds or import sounds from a file that is not open.
Rule Set
Put rules into a Rule Set if you want one set of rules to be checked separately from all other rules in the list
outside the set. There are 3 types of rule sets: Do First Match, Randomize & Do First, and Do All &
Continue.