Cocoa Basics Tutorial

download Cocoa Basics Tutorial

of 51

Transcript of Cocoa Basics Tutorial

  • 8/8/2019 Cocoa Basics Tutorial

    1/51

    Tutorial for Cocoa:

  • 8/8/2019 Cocoa Basics Tutorial

    2/51

    Cocoa Basics Tutorial

    Welcome to the Cocoa Basics Tutorial. We'll create a simple world you can play, enhance, and evenshare with your friends on the Web!

    You need to have downloaded and installed Cocoa before taking this tutorial.

    Table of Contents

    Introduction

    Create a Piece

    Write a "Move Right" Rule

    Write "Jump" Rules

    Example world

    Puzzle to try

    Go to the Beyond the Basics section

    Get help with the tutorial setup

    Download all the movies in the tutorial

    (430K--You can open them with MoviePlayer)

    (Note that the hyperlinks indicated on these pages do not work,but they would work on the online version of this Tutorial)

    Copyright 1997 Apple Computer, Inc.Apple, the Apple logo, and Cocoa are trademarks of Apple Computer, Inc. registered in the United States and other

    countries.

    Maintained by the Apple Cocoa DR Team. Last updated Fri, June 20 1997.

    E-mail [email protected] with problems or questions.

  • 8/8/2019 Cocoa Basics Tutorial

    3/51

    basicforPDF.html Page 1

    Mon, Jun 23, 1997 12:10 PM

    Welcome to the Basics Tutorial for Cocoa!

    The Basics section will help new users learn the basics to building worlds in Cocoa.

    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 adefinition 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 writingrules of behavior. All pieces which have rules and are on the board get a chance to try their rules onevery clock tick.

    There are 2 steps to getting started:

    1. Create a piece and its appearance.

    2. Write a rule that makes the piece do something.

    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 jumpingon 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 aminute to download.

    When you open Cocoa, click the "Open Saved World" button.

  • 8/8/2019 Cocoa Basics Tutorial

    4/51

    basicforPDF.html Page 2

    Mon, Jun 23, 1997 12:10 PM

    Then open the "Starter World" to follow along with this tutorial.

    TO CREATE A NEW PIECE

    In Cocoa, you start by creating a piece and giving it an appearance. Try not to spend too much timedrawing. You can use a picture that has been drawn in another program or one from the Scrapbook.

    1. Click on the.. .. create tool

    The cursor turns into the create tool.

    Click anywhere above the ground pieces to create new piece on the board.

    A new piece looks like a splat of paint.

  • 8/8/2019 Cocoa Basics Tutorial

    5/51

    basicforPDF.html Page 3

    Mon, Jun 23, 1997 12:10 PM

    What a piece looks like is called its appearance. You can change a piece's appearance with the paint

    tool.

    2. Click on the.. .. paint tool

    The cursor turns into the paint tool.

    Click on the piece with the paint tool.

    This opens the Appearance Editor where you can draw an appearance.

    3. Click on .. ..to clear this appearance out of the Appearance Edito

  • 8/8/2019 Cocoa Basics Tutorial

    6/51

    basicforPDF.html Page 4

    Mon, Jun 23, 1997 12:10 PM

    You can draw any appearance you like, or paste in any picture copied from another program into theAppearance editor. Use an appearance that takes up only one square on the Cocoagrid.

    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.

    TO WRITE A "MOVE RIGHT" RULE

    The second step is to write a rule that shows your piece what to do. You want your pieces to act acertain way when they are in a certain situation. To get through the obstacle course, the first thingyour 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 willmove right.

  • 8/8/2019 Cocoa Basics Tutorial

    7/51

    basicforPDF.html Page 5

    Mon, Jun 23, 1997 12:10 PM

    1. Click on the.. .. rule recording tool.

    The cursor turns into the rule recording tool.

    Click on your piece with the rule recording tool.

    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 aroundyour piece.

    Before you do anything, the before and after sides in the Rule Editor are the same as what's in thespotlight on the board.

    When you're writing a rule and you do something with your piece, those actions get recorded as arule. You can show your piece what to do either in the spotlight on the board or the after side ofthe Rule Editor.

  • 8/8/2019 Cocoa Basics Tutorial

    8/51

    basicforPDF.html Page 6

    Mon, Jun 23, 1997 12:10 PM

    Before a rule will work, the left side of the Rule Editor must match what's on the board. It's calledthe BEFORE SIDE of the rule. When a rule works, the actions that were recorded when you wrotethe rule get done. Those recorded actions are shown on the right side of the Rule Editor. It's calledthe 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 boardand 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.

    Here's how to write this "Move Right" rule.

    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 willignore 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 themouse over the piece, click down on the mouse button and drag.

    3. Drag your piece into the empty space to the right.

    You have now written a rule that says:

    If the space to the right of me is empty . . . then move into it.

  • 8/8/2019 Cocoa Basics Tutorial

    9/51

    basicforPDF.html Page 7

    Mon, Jun 23, 1997 12:10 PM

    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..

    ..to stop the clock.

    Your piece will keep moving right as long as nothing gets in its way. Now you can putin some obstacles for your piece to jump around.

    TO BUILD AN OBSTACLE COURSE

    To build a world, you break up the actions into small steps and you write rules for the pieces toperform the small steps. In the obstacle course world, you create obstacles and you write rules thatwill tell your piece to jump ON and OFF an obstacle. It takes 2 small jumps rather than one big leapover an obstacle.

    LOOK BEFORE YOU LEAP! Your pieces only know what you tell them to do. You want yourpieces 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 anew rule.

    After you write rules that tell your piece when to jump, you can set up an obstacle course for yourpiece to jump around.

  • 8/8/2019 Cocoa Basics Tutorial

    10/51

    basicforPDF.html Page 8

    Mon, Jun 23, 1997 12:10 PM

    But first, you need to make a second piece to be the obstacles in this world.

    TO MAKE A SECOND PIECE: THE OBSTACLE

    1. Click on the.. ..create tool.

    The cursor turns into the create tool.

    Click to the right of your piece to create a new piece on the board.

    A new piece looks like a splat of paint.

    What a piece looks like is called its appearance. You can change a piece's appearance with the painttool.

    2. Click on the.. .. paint tool.

    The cursor turns into the paint tool.

  • 8/8/2019 Cocoa Basics Tutorial

    11/51

    basicforPDF.html Page 9

    Mon, Jun 23, 1997 12:10 PM

    Click on the new piece 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. Startthe 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 aboveis 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 isempty.

    TO WRITE A "JUMP ON" RULE

  • 8/8/2019 Cocoa Basics Tutorial

    12/51

    basicforPDF.html Page 10

    Mon, Jun 23, 1997 12:10 PM

    1. Set up the board, then click on the.. .. rule recording tool.

    The cursor turns into the rule recording tool.

    Click on your piece with the rule recording tool.

    This opens the Rule Editor where you record a rule.

    2. Drag the spotlight handles to include the block in the space to the right and the empt

    spaces above your piece and the block.

    3. Then drag your piece on top of the block.

    The board has a grid pattern and you can only move pieces into spaces marked by the squares of thegrid.

    You have now written a rule that says:

    If there's a block to the right of me and the space above is empty . . . then jump on the block.

  • 8/8/2019 Cocoa Basics Tutorial

    13/51

    basicforPDF.html Page 11

    Mon, Jun 23, 1997 12:10 PM

    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 getyour piece down off of the block.

    TO WRITE A "JUMP DOWN" RULE

    Now you will write a rule for you piece to jump down. Here's the situation: if your piece is on top ofa block and the space to the right of the block is empty, then your piece will jump down off of theblock into that space.

    For this rule, your piece is already in the position you want, so you can go ahead and write the rule.

    1. The board is already set. Click on the.. .. rule recording tool.

    The cursor turns into the rule recording tool.

    Click on your piece with the rule recording tool.

    This opens the Rule Editor where you record a rule.

    2. Drag the spotlight handles to include the block below your piece and the empty spac

    to the right.

  • 8/8/2019 Cocoa Basics Tutorial

    14/51

    basicforPDF.html Page 12

    Mon, Jun 23, 1997 12:10 PM

    3. Then move your piece down off of the block.

    You have now written a rule that says:

    If I'm on top of a block and the space to the right of the block is empty . . . thenjump 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..

    ..to stop the clock.

    Your piece will move right until it reaches the block. It will jump on and off the block and thencontinue to move right.

    Now you can put more blocks on the board and see if your piece can make it through the obstaclecourse you build.

    Also, you can name the pieces to avoid confusion later.

  • 8/8/2019 Cocoa Basics Tutorial

    15/51

    basicforPDF.html Page 13

    Mon, Jun 23, 1997 12:10 PM

    1. Go to the PIECE menu and select "Show Types."

    2. Name the Block and your piece in Types window.

    3. Drag more blocks from Types window to the board.

    Anytime you want to name your types of pieces or get more pieces of any type, go to the PIECEmenu and select "Show Types."

    TRY THIS ON YOUR OWN!

    In this world, your piece can move around in different ways. Set up the board like the exampleshown here to see how your piece can use these 3 rules - move right, jump on and jump down - tomove through these different obstacles.

    It can jump over and off a pile of blocksIt can jump over and off a row of blocks

  • 8/8/2019 Cocoa Basics Tutorial

    16/51

    basicforPDF.html Page 14

    Mon, Jun 23, 1997 12:10 PM

    Try some of your own experiments by moving or adding more blocks.

    What's the largest number of obstacles your piece can move around without going off the right side

    of the screen?

    SAVING YOUR WORLD

    You have 3 options for saving Cocoa worlds.

    Go to the Saving Options page to see how.

    GET A COPY OF THIS WORLD

    You can download the "Obstacle Course" world to your computer. It's about 15K and willtake 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

  • 8/8/2019 Cocoa Basics Tutorial

    17/51

    basicforPDF.html Page 15

    Mon, Jun 23, 1997 12:10 PM

    Cocoa mascot run through this obstacle course.

    TRY THESE PUZZLES

    Add new obstacles and rules to your piece to make it run through a different obstacle course:

    Here are some rules you can try...

    Go down under a new piece, for instance, a circle.Go up around the new piece.

    SAVING YOUR WORLD

    You have 3 options for saving Cocoa worlds.

    Go to the Saving Options page to see how.

  • 8/8/2019 Cocoa Basics Tutorial

    18/51

    basicforPDF.html Page 16

    Mon, Jun 23, 1997 12:10 PM

    GET A COPY OF THIS WORLD

    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 theblocks.

    Try some of your own experiments by adding different obstacles and giving rules for your piece todo more.

  • 8/8/2019 Cocoa Basics Tutorial

    19/51

    beyondforPDF.html Page 1

    Mon, Jun 23, 1997 12:11 PM

    Beyond the Basics

    Your piece can do many different things. Choose one of the following to see how to write a rule to doit.

    After you've seen one, you can come back and choose a different one.

    Change my appearance - "Turning Around"

    Delete another piece - "Eating Food"

    Move another piece - "Moving Obstacles"

    Create another piece - "Creating Obstacles"

    Say a Sound - "Making Sound"

    Use Rule Sets - "Group Rules Together"

    If you'd rather skip the tutorial, you can get these worlds now. See below.

    GET A COPY OF THESE WORLDS

    You can download the "Beyond Basics" worlds to your computer. It's 95K and will takeabout 2 minutes to download with a 14.4 speed modem. You will get a folder with all the worldsready for you to see.

    Each world has the rules already written for the Cocoa mascot. You can open one and start the clockto see the mascot run through the obstacle course.

    Start a new world by copying the "Obstacle Course" world done in the "Basics" section. If youskipped that section, download the "Obstacle Course" world and start with it to go on withthis section.

    To avoid confusion, rename the new world "Turning Around" before opening it.

  • 8/8/2019 Cocoa Basics Tutorial

    20/51

    beyondforPDF.html Page 2

    Mon, Jun 23, 1997 12:11 PM

    CHANGE MY APPEARANCE

    Your piece already knows how to move right when it has a certain appearance and when its in acertain situation. Appearances are important. If the appearance changes, the situation changes andyour 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.

    CREATE A SECOND APPEARANCE

    1. Select your piece on the board (it looks dark), go to the APPEARANCE menu and

    select "Show Appearances."

    This opens the Appearances window. Any time you want to see all the appearances a piece has, justgo to the APPEARANCE menu and select "Show Appearances."

    2. Go to the APPEARANCE menu and select "New Appearance."

    This opens the Appearance Editor for your piece with a COPY of the first appearance it had. You canchange this new appearance so that your piece faces to the left.

  • 8/8/2019 Cocoa Basics Tutorial

    21/51

    beyondforPDF.html Page 3

    Mon, Jun 23, 1997 12:11 PM

    In this example, the appearance will be flipped so that the Cocoa mascot is facing left.

    3. Go to the PAINT menu and select "Flip Left-Right."

    Now, 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.

  • 8/8/2019 Cocoa Basics Tutorial

    22/51

    beyondforPDF.html Page 4

    Mon, Jun 23, 1997 12:11 PM

    Now that your piece has 2 appearances, you can write the rule that will change your piece'sappearance.

    TO WRITE "TURN AROUND" RULE

    You want your pieces to act a certain way when they are in a certain situation. Appearances areimportant. 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 newsituation.

    Here, we want to set up this situation: if your piece is moving to the right, but there are 2 blocks in itsway, 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 pieceshould 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.)

    1. Set up the board, then click on the.. .. rule recording tool.

    The cursor turns into the rule recording tool.

    Click on your piece with the rule recording tool.

    This opens the Rule Editor where you write the rule.

    2. Drag the spotlight handles to include the 2 blocks to the right.

  • 8/8/2019 Cocoa Basics Tutorial

    23/51

    beyondforPDF.html Page 5

    Mon, Jun 23, 1997 12:11 PM

    Now you show that you want the appearance to change.

    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.

    You have now written a rule that says:

    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.

    AN IMPORTANT NOTE ABOUT APPEARANCES

    If you dragged the Cocoa mascot's "appearance 2" onto the Block in the rule, the Block wouldn'tchange its appearance to look like the Cocoa mascot. When you're changing appearances, be carefulto check who's Appearances you're using and which piece you're dragging that appearance onto.

  • 8/8/2019 Cocoa Basics Tutorial

    24/51

    beyondforPDF.html Page 6

    Mon, Jun 23, 1997 12:11 PM

    TRY THIS ON YOUR OWN!

    Now that your piece has turned to the left, it doesn't know what to do next. If you run the world, itwill 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 tomove the piece left.

    The next thing your piece might do is jump on then off the block when it's moving left. If you needhelp, go back to the Jump section, to see how that was done.

    Here are some rules you can try...

  • 8/8/2019 Cocoa Basics Tutorial

    25/51

    beyondforPDF.html Page 7

    Mon, Jun 23, 1997 12:11 PM

    SAVING YOUR WORLD

    You have 3 options for saving Cocoa worlds.

    Go to the Saving Options page to see how.

    GET A COPY OF THIS WORLD

    You can download the "Turning Around" world to your computer to see what the finishedworld 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 youskipped that section, download the "Obstacle Course" world and start with it to go on withthis section.

    To avoid confusion, rename the new world "Eating Food" before opening it.

    DELETE OTHER PIECE IN A RULE

    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 ofrule you write when youwant 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.

    TO MAKE ANOTHER PIECE

    1. Click on the.. ..create tool.

    The cursor turns into the create tool.

  • 8/8/2019 Cocoa Basics Tutorial

    26/51

    beyondforPDF.html Page 8

    Mon, Jun 23, 1997 12:11 PM

    Click to the right of your piece to place the new piece on the board.

    A new piece looks like a splat of paint.

    What a piece looks like is called its appearance. You can change a piece's appearance with the painttool.

    2. Click on the.. .. paint tool.

    The cursor turns into the paint tool.

    Click on the new piece 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, thencopy and paste it in as an appearance. Here, use an appearance that takes up only one square on thegrid.

    3. Click on the painting tools to draw the appearance or paste one in.

  • 8/8/2019 Cocoa Basics Tutorial

    27/51

    beyondforPDF.html Page 9

    Mon, Jun 23, 1997 12:11 PM

    The Cocoa mascot likes to eat jellybeans. Yum, yum!

    You're done with the appearance. Click the.. ..appearance done button.

    TO WRITE THE "EAT FOOD" RULE

    You want your pieces to act a certain way when they are in a certain situation. To do this, you set upthe pieces on the board BEFORE you write the rules which tell them how to act. If your pieces arenot 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.

    1. Set up the board, then click the.. .. rule recording tool.

    The cursor turns into the rule recording tool.

    Click on your piece with the rule recording tool.

    This opens the Rule Editor where you record a rule.

  • 8/8/2019 Cocoa Basics Tutorial

    28/51

    beyondforPDF.html Page 10

    Mon, Jun 23, 1997 12:11 PM

    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 deletetool.

    3. Click on the food with the.. .. delete tool.

    4. Move your piece to the right.

    You have now written a rule that says:

    If there is food in the space to the right of me . . . then "eat" it and move to theright.

    You're done with this rule. Click the.. ..rule done button.

    Now you can put out more food for your piece to eat.

  • 8/8/2019 Cocoa Basics Tutorial

    29/51

    beyondforPDF.html Page 11

    Mon, Jun 23, 1997 12:11 PM

    1. Go to the PIECE menu and select "Show Types."

    If you want, you can name the type "Food" in the Types window.

    2. Drag more food from Types window to the board.

    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.

    TRY THIS ON YOUR OWN!

    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.

  • 8/8/2019 Cocoa Basics Tutorial

    30/51

    beyondforPDF.html Page 12

    Mon, Jun 23, 1997 12:11 PM

    Here are some rules you can try...

    SAVING YOUR WORLD

    You have 3 options for saving Cocoa worlds.

    Go to the Saving Options page to see how.

    GET A COPY OF THIS WORLD

    You can download the "Eating Food" world to your computer to see what the finished worldlooks like. It's 23K and will take about 1 minute to download with a 14.4 speed modem.

  • 8/8/2019 Cocoa Basics Tutorial

    31/51

    beyondforPDF.html Page 13

    Mon, Jun 23, 1997 12:11 PM

    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 youskipped that section, download the "Obstacle Course" world and start with it to go on withthis section.

    To avoid confusion, rename the new world "Moving Obstacles" before opening it.

    MOVE THE OTHER PIECE

    Your piece already knows how to move right and jump on and off a block. How about giving yourpiece some rules to change the obstacle course? As it moves around the board, it can moveobstacles 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.

    TO WRITE A "MOVE BLOCK" RULE

    You want your pieces to act a certain way when they are in a certain situation. You can change thesituation 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 yourpiece, 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 tothe right of your piece, stack 2 blocks, one above the other.

    1. Set up the board, then click on the.. .. rule recording tool.

    The cursor turns into the rule recording tool.

    Click on your piece with the rule recording tool.

  • 8/8/2019 Cocoa Basics Tutorial

    32/51

    beyondforPDF.html Page 14

    Mon, Jun 23, 1997 12:11 PM

    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

    piece and one empty space to its left.

    3. Move the top block to the empty space to the left of your piece.

    You have now written a rule that says:

    If there are 2 blocks, one above the other, to the right of me, move the top block tothe space to my left, only if that space is empty.

    You're done with this rule. Click the.. ..rule done button.

    TRY THIS ON YOUR OWN!

    What if the space to the left of your piece is not empty? Then, your piece could not move one of the

  • 8/8/2019 Cocoa Basics Tutorial

    33/51

    beyondforPDF.html Page 15

    Mon, Jun 23, 1997 12:11 PM

    blocks.

    Write some other rules that will let your piece move one of the blocks to a different empty spaces, forinstance, on the right side of the block or down below the block.

    Here are some rules you can try...

    SAVING YOUR WORLD

    You have 3 options for saving Cocoa worlds.

    Go to the Saving Options page to see how.

  • 8/8/2019 Cocoa Basics Tutorial

    34/51

    beyondforPDF.html Page 16

    Mon, Jun 23, 1997 12:11 PM

    GET A COPY OF THIS WORLD

    You can download the "Moving Obstacles" world to your computer to see what the finishedworld 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 youskipped that section, download the "Obstacle Course" world and start with it to go on withthis section.

    To avoid confusion, rename the new world "Creating Obstacles" before opening it.

    CREATE ANOTHER PIECE IN A RULE

    Your piece already knows how to move right and jump on and off a block. How about giving yourpiece some rules to build the obstacle course itself? As it moves around the board, it can create newobstacles and then it will have to get around them.

    TO WRITE THE "CREATE A BLOCK" RULE

    You want your pieces to act a certain way when they are in a certain situation. You can change thesituation by adding obstacles, or you can give rules to your piece to add obstacles while it movesthrough the obstacle course.

    Here, we want to set up this situation: if there are 2 blocks, one above the other, to the right of yourpiece, 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.

    1. Set up the board, then click on the.. .. rule recording tool.

    The cursor turns into the rule recording tool.

    Click on your piece with the rule recording tool.

  • 8/8/2019 Cocoa Basics Tutorial

    35/51

    beyondforPDF.html Page 17

    Mon, Jun 23, 1997 12:11 PM

    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.

    3. Move your piece up into the empty space above it.

    To create another block in the rule, you need to see all the types for this world and make a copy of theblock.

    4. Go to the PIECE menu and select "Show Types."

  • 8/8/2019 Cocoa Basics Tutorial

    36/51

    beyondforPDF.html Page 18

    Mon, Jun 23, 1997 12:11 PM

    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" thendrag out any piece you want onto the board.

    You have now written a rule that says:

    If there are 2 blocks, one above the other, to the right of me . . . I'll move up andanother block will appear under me.

    You're done with this rule. Click the.. ..rule done button.

    TRY THIS ON YOUR OWN!

    Write other rules that will let your piece move in other directions and make obstacles appear in theempty spaces. But be careful, if you write too many rules that create obstacles, there will soon be nospace to move around!

  • 8/8/2019 Cocoa Basics Tutorial

    37/51

    beyondforPDF.html Page 19

    Mon, Jun 23, 1997 12:11 PM

    Here's another rule you can try...

    SAVING YOUR WORLD

    You have 3 options for saving Cocoa worlds.

    Go to the Saving Options page to see how.

    GET A COPY OF THIS WORLD

    You can download the "Creating Obstacles" world to your computer to see what the finishedworld 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.

  • 8/8/2019 Cocoa Basics Tutorial

    38/51

    beyondforPDF.html Page 20

    Mon, Jun 23, 1997 12:11 PM

    Start a new world by copying the "Obstacle Course" world done in the "Basics" section. If youskipped that section, download the "Obstacle Course" world and start with it to go on withthis 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 itmake sound as it moves around. This is a good way to attract attention to something differenthappening 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 wayand 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 soundwhen 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 goto the SOUND menu and select "Show Sounds."

    We want to create a new sound.

    2. Go to the SOUND menu and select "New Sound."

  • 8/8/2019 Cocoa Basics Tutorial

    39/51

    beyondforPDF.html Page 21

    Mon, Jun 23, 1997 12:11 PM

    This opens the Sound Editor for your piece with Record, Stop and Play buttons.

    3. Make certain your microphone is working.

    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.

    4. Click on the.. . .button to start recording and the.. ..button to stop

    recording the sound.

    5. Click on the.. ..button to hear the sound.

    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

  • 8/8/2019 Cocoa Basics Tutorial

    40/51

    beyondforPDF.html Page 22

    Mon, Jun 23, 1997 12:11 PM

    you're happy with what you recorded, click on the.. ..button.

    The new sound appears in the Sounds window. To avoid confusion later, you can name it "Uh Oh."

    You can double-click on the.. ..sound to hear it again.

    Now that your piece has a sound to say, you can write the rule that lets your piece say the soundwhen the world runs.

    WRITE A "SAY SOUND" RULE

    You want your pieces to say a certain sound when they are in a certain situation. Sounds make yourworld 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 2blocks 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.

    1. Set up the board, then click on the.. .. rule recording tool.

    The cursor turns into the rule recording tool.

    Click on your piece with the rule recording tool.

  • 8/8/2019 Cocoa Basics Tutorial

    41/51

    beyondforPDF.html Page 23

    Mon, Jun 23, 1997 12:11 PM

    This opens the Rule Editor where you write the rule.

    2. Drag the spotlight handles to include the 2 blocks to the right.

    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".

    You have now written a rule that says:

    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.

  • 8/8/2019 Cocoa Basics Tutorial

    42/51

    beyondforPDF.html Page 24

    Mon, Jun 23, 1997 12:11 PM

    AN IMPORTANT NOTE ABOUT SOUNDS

    If you dragged the Cocoa mascot's "Uh Oh" sound onto the Block in the rule, the Block wouldn'tsay "Uh Oh." When you're making sounds, be careful to check whose Sounds you're using andwhich piece you're dragging that sound onto.

    TRY THIS ON YOUR OWN!

    Now that your piece says something in one situation, you can record other sounds to have it say otherthings in other situations. If you add another of the same piece into the world, you can have themmeet and say "Hello" or "Goodbye".

    Here are some rules you can try...

  • 8/8/2019 Cocoa Basics Tutorial

    43/51

    beyondforPDF.html Page 25

    Mon, Jun 23, 1997 12:11 PM

    SAVING YOUR WORLD

    You have 3 options for saving Cocoa worlds.

    Go to the Saving Options page to see how.

    GET A COPY OF THIS WORLD

    You can download the "Making Sound" world to your computer to see what the finishedworld 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.

    GROUPING RULES INTO A RULE SET

    If you've built the worlds described in the Beyond the Basics section, you've written manydifferent rules, some for the same situation: when there are 2 blocks, one above the other to the rightof your piece. All rules are checked from the top to the bottom of the rule list. But, you may notalways 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.

    TRY THIS ON YOUR OWN!

    Open the Rules window by double-clicking on a piece.

    Then click on the.. .. Rule Set tool.

    The cursor becomes a Rule Set tool. Click in any white space between the rules.

  • 8/8/2019 Cocoa Basics Tutorial

    44/51

    beyondforPDF.html Page 26

    Mon, Jun 23, 1997 12:11 PM

    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

    Say "Uh Oh"

    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.

  • 8/8/2019 Cocoa Basics Tutorial

    45/51

    beyondforPDF.html Page 27

    Mon, Jun 23, 1997 12:11 PM

    Notice that there are rules below the rule set. Because the rules are checked from the top to the bottomof the rule list, the rules below the rule set will only be checked if none of the rules inside the rule setwork or if you choose a different rule set type.

    You can change how the rule set works:

    Put the pointer over the options and mouse-down to see the pop-up menu.

    Choose one rule set option and run the world to see how the piece acts differently, depending onwhich rule set option you choose.

    Do First Match finds the FIRST rule in the rule set that works, it performs the actions and thenanother piece gets a turn.

    When to use this: Keep rules together if you want one set of rules to be checked in the order thatthey are listed, but separately from all other rules in the rule list outside the set. For instance, put allof your piece's "Move" rules in a Do First Match rule set. If you want it to move right every time thatit 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 piecegets 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, ifyou put all of your piece's "Move" rules in a Randomize & Do First rule set, it will move in differentdirections rather than the same direction on every clock tick.

  • 8/8/2019 Cocoa Basics Tutorial

    46/51

    beyondforPDF.html Page 28

    Mon, Jun 23, 1997 12:11 PM

    Do all and Continue: the rule order stays the same, but it finds ALL the rules in the Rule Set thatwork, it performs ALL the actions in those rules that it can and then it GOES ON to check the rulesthat 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 DoAll & Continue rule set. For instance, you can "Add 1 to Age" so that your piece will get older, and itwill GO ON to check if it can do something else on the same clock tick.

    GET A COPY OF THIS WORLD

    You can download the "Grouping Rules" world to your computer. It's about 28K and willtake about 1 minute to download with a 14.4 speed modem.

  • 8/8/2019 Cocoa Basics Tutorial

    47/51

    Saving Options

    You can save your Cocoa world in 3 ways:

    As a Cocoa world which can only be opened with Cocoa

    As a web page which can be viewed with a web browser

    As an autoplaying world which can be viewed on any Macintosh

    Save World or Save World As...

    Type in the name you'd like to use for your world or this version of your world.

  • 8/8/2019 Cocoa Basics Tutorial

    48/51

    Saving Worlds this way allows you to open them in Cocoa and change how they work later. Theother two formats don't let you do this.

    Save for Internet

    First, fill in the information to be shown in the web page

    After you fill in the information, you can "Save for Internet"

  • 8/8/2019 Cocoa Basics Tutorial

    49/51

    A ".cco" media file and a ".html" web page file will be created. The web page can be opened with aweb 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

  • 8/8/2019 Cocoa Basics Tutorial

    50/51

    Word List

    WorldIn a world, pieces can act in certain ways only when in a certain situation. Pieces don't act the same way allthe time. How they act depends on the situation you create in the world. You write rules to control howpieces act in the world.

    BoardThe Board is the area where the pieces act. The pieces can only act in the order which they were put out onthe board.

    PieceAnything 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 cahave many pieces of the same Type, all acting on the Board at once. You can move, create, delete, copy, anname 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 withactions to do (the right side of the Rule). All the rules for a piece are listed in the Rules window. The rulesare in the order that will be checked for the piece to act. You can create, delete, name, and reorder a rule.

    Clock TickIn one clock tick, every piece gets a chance to test its rules and do what it can. A clock tick can run eitherforward so all pieces can try to do something or it can run backward so all pieces UNDO everything they dion the last clock tick.

    AppearanceWhat the piece looks like. You can draw an appearance in Cocoa or paste one in that you drew and copiedfrom a drawing program. Pieces can have many different appearances.

  • 8/8/2019 Cocoa Basics Tutorial

    51/51

    GridThe Board is separated into a grid of squares like a checkerboard. When you draw an appearance or write arule, you can see the grid lines in the background. When pieces move around in a world, they can only movfrom square to square on the grid.

    Painting ToolsA set of tools for drawing your piece's appearance; for example, pencil, paintbrush, and eraser. There is aPAINT 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 outo show more of the board and to include pieces that should be in the rule. Your piece sees what's in thespotlight and it ignores anything outside the spotlight.

    VariableInformation about pieces such as their appearance or what they said. Pieces can track different variables andthe variables can keep different kinds of information. You can create, delete, move, and name a variable.

    Delete toolThe delete tool is used to delete anything that you want to delete out of your world, for example, pieces or

    rules.

    SoundWhat the piece can say. You can record new sounds or import sounds from a file that is not open.

    Rule SetPut rules into a Rule Set if you want one set of rules to be checked separately from all other rules in the listoutside the set. There are 3 types of rule sets: Do First Match, Randomize & Do First, and Do All &Continue.