Tutorial: Part One of Methods

By Deborah Nelson
Duke University, July 9, 2008

Under the direction of Professor Susan Rodger

Tutorial: Methods

As you follow the instructions below, click on an image to enlarge it.

Then use the'go back one page' arrow in your web browser to come back to this tutorial.

Loading the World

Either set up your world, or download the file that we'll be working with today here. Save it in a directory that you can find again, and then start Alice and open the world. NOTE: You cannot double-click the file to open it; Windows will not know what to use, and even if you select Alice from a list of programs, the loading will fail.

First: After you have opened the file, and set up your world, go into the "Layout" mode by clicking on the green button 'Add Objects' (toward the middle of screen)

Click 'more controls.' Click 'drop a dummy at the camera.' Rename the dummy 'originalPosition.' To leave the layout mode, click 'done' This is something you should always do when you make a world in case you need to return the camera to this view later. If you don't understand dummys,look at the camera control tutorial again.

Part 1: A method is:

A method is a sequence of instructions that will be carried out when requested. Remember, built in methods are primitive instructions every character already knows how to perform. You use them to create new methods so that the characters can do more. The two types of methods are class-level and world-level.

Part 2: Class-level methods

A class-level method defines the behavior for a single character.

Step 1: How to create a class-level method:

Step 2: How to write a method:

Step 3: To call your method:

Step 4: Writing a method for kangaroo:

Part One of the Code (click on the image to enlarge it):

Part Two of the Code:

  • Remember, to call your method to test it. Click on world.myfirst method to get back to it and then delete what you have there. Drag kangaroo.hop into it. Push the 'play' button to watch the kangaroo hop.
  • Part 3: World-level methods:

    A world-level method has characters that interact with each other.

    Step 5: Writing a world-level method:

    Step 6: Loops

    Congratulations on creating your first methods. Save this world. We will add to it again in later tutorial.