Creating Functions Tutorial

By Deborah Nelson
Duke University, July 22, 2008

Under the direction of Professor Susan Rodger



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

For this tutorial, download the starter world here

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


Play your world

Part 1: Functions

Types of Functions


Part 2: creating a function

Step 1: What type of function to create

Step 2: How to create a function


Part 3: Writing the function

Step 1: The parameter

Step 2: The if/else

Step 3: The conditional

The Return

Nested if statements

Step 6: Finish the function


Part 4: Calling the function


Part 5: One more error

Step 1: Writing the new function: is it burned?

Step 2: Return statements


Step 3: Create a new parameter

Step 4: Nest an if/else


Part 6: Calling the function notBurned

Play your world


Recap