Learning to program with Alice

Meet Alice! Alice is an incredibly fun program that has been made freely available as a public service by Carnegie Melon University.

The great part about Alice is that you'll start learning the basics of computer programming without even knowing it! Just have fun exploring and creating your own virtual world!

Getting Started edit

You can freely download the Alice program from http://alice.org/, but it's quite large (over 100Mb) so if you're in a class then you may want to check whether someone else has already downloaded it!

Once it's downloaded, unzip the file into a location on your computer (such as the C:\Temp). Now if you look inside the Alice folder that's been created for you (ie. C:\Temp\Alice) you'll see a file called Alice.exe - just double-click on it to get started!

Tutorial 1: Ice skater edit

When Alice loads up, click on the big "Start the Tutorial" button and you'll be taken step-by-step through a fun activity... just watch that skater dance!

Activity 1: After finishing the first tutorial, see if you can get your ice-skater to skate out a square!

Tutorial 2: Crushing the phone edit

You might want to take a break or go on directly to the second tutorial.

Activity 2: When you finish the second tutorial, come back to tutorial 1 (the Ice Skater), and have a go at adding a new method for the skater called Do Square. Whenever your skater's Do Square method is called, she should do exactly that!

Now might be a good time to think a bit about what you've learned so far. If you keep a blog for your own thoughts/learning/fun, why not take 5mins now to summarise what you've learned so far, then ask someone you know to comment on your blog with some feedback!

Tutorial 3: A sing-a-long edit

After completing tutorial 3, you're ready to create your first computer game! Can you believe it?!

Activity 3: Come back again to tutorial 1 (the Ice Skater), and try adding some events so that when you press the arrow keys your skater skates in that direction. You could even add the spacebar as a jump button!

Hint: You might need to create two new methods: Turn Left and Turn Right.

Make sure you save your Ice Skater example world in your own folder as we'll build on this later.

Tutorial 4: Creating your own Beach scene edit

The fourth tutorial will show you how you can create your own scenes, using all the great 3D models that come for free with Alice!

Activity 4: When you finish this tutorial, you'll be ready to start your own project! Start creating your own world and having a look at all the different available objects!

Activity 5: Learning about Variables edit

Opening up your own Ice Skater example world again:

  • If you haven't already done so, add an event so that when the space bar is pressed your skater jumps.
  • Test your program to make sure that this works.

We're going to get our ice skater to remember how many times she's jumped during her performance! But to do this, we'll first need to create a variable. Just think of a variable as a container where you can store things.

  • Click on the Iceskater object in the object browser and select the Properties tab of the IceSkaters details.
  • Click on the Create New Variable button.
  • Give your variable the name howmanyjumps. By creating this variable for our IceSkater, we can get her to remember how many jumps she's done. Set the type of the variable to Number and set it's initial value to 0 (as she hasn't jumped yet!)

Next we need to make sure that whenever our Ice Skater jumps, she adds 1 to our variable howmanyjumps:

  • Click on the Methods tab of the IceSkaters details.
  • Click on the Edit button next to the Jump method, as we want to change what happens whenever she jumps
  • You'll then see a lot of code (that's the code to make her jump). If it worries you, click on the '-' next to "Do Together" at the top to minimize all the code.
  • Click back on the Properties tab of the IceSkater details and drag your howmanyjumps variable over to the end of the Jump code (it should be just after the last "IceSkater Set Pose" command.)
  • When you drop your variable their, you'll be able to tell Alice what you want to do with it. Choose the option to increment your variable by 1.

Try running your world again... notice any difference?

That's right, it doesn't seem any different yet! Even though our new bit of code is working, we haven't done anything to help us see what's going on! To do so, we'll need to use an if statement!

Activity 6: Using IF-Statements in ALICE edit

If-statements are one of the most useful tools of computer programmers, as they allow your programs to make decisions!

We're going to modify our IceSkaters Jump method so that if she's jumped twice already, the next time we press the space bar she'll just say "I'm too tired to jump anymore!".

Here's the steps:

  • Click on the Edit button of your Iceskaters Jump method,
  • From the bottom of the screen, drag in the If/Else statement and drop it at the top of your Jump method. When you let go of the mouse button, you will be asked to choose the condition for your If statement... just choose "true" for the moment.

Now, we want to do something special when our IceSkater has jumped twice, ie. when our howmanyjumps variable is equal to 2. To make this happen:

  • Look at your Iceskaters Properties, and drag your howmanyjumps variable into your if statement (where it currently says "true").
  • When you drop your variable in the right spot, you will be asked what you want to set as the condition. We want to say something like "If howmanyjumps is equal to 2". See if you can make this happen (Hint: in computer programming "is equal to" is often represented by two equal signs ==.)

At this point, you'll notice that your If statement says:

 If howmanyjumps == 2 then 
    Do Nothing, 
    Do Nothing 

We can now choose what we will do when she's jumped twice, and what she'll do otherwise:

  • Looking back at the methods for your IceSkater, you'll find there a method called Say. Drag this method and drop it onto the first "Do Nothing" of your If Statement. You'll be prompted as to what you want to say, choose Other and set the text to "I'm too tired to jump any more. Sorry."
  • If our IceSkater hasn't yet jumped twice, we just want her to do her normal thing, so drag all the statements that are below your If statement into the Else section of your If statement (where the remaining "Do Nothing" is).

Now test your program! You should find that your IceSkater will jump twice, but after that will tell you she's too tired.

Practice: To practice creating variables and using IF statements, we're going to modify our program so that our IceSkater gets dizzy if she spins too much! Here's some tips to get started:

  • Add a new event so that when the 'S' key is pressed, your skater spins (and test to make sure it works).
  • Create a new variable for your IceSkater called howmanyspins (set to 0 initially).
  • Edit your Iceskaters Spin method so that after all the other code, your new variable is incremented by 1.
  • Add an IF statement to your Spin method so that if your IceSkater has already done two spins she says "I'm feeling dizzy. Sorry.", otherwise she should do her normal Spin.

Test to make sure it works and get someone else to take a look at your work!

Activity 7: Using While-loops in ALICE edit

To be completed.

A design project edit

Now the fun begins... Let your imagination run wild and create your own interactive world!

Your situation is this: A recruiter at KidzWorks - a company that designs interactive computer experiences for toddlers - has heard some good reports about your creative abilities with computers (through your facilitator of course!). Her name is Janet and she's keen to see your creative flair in action. Janet's asked you to build a small interactive environment for 3-5 year olds. Here's what Janet's written:

Hi! Thanks for taking up this challenge! I hope it will be a rewarding experience for you too! Basically, we're keen to create small interactive worlds that young kids can play with - similar to the singing penguins that you should have already seen when you were learning Alice, but something of your own! Feel free to be creative, but be careful not to make your project too complicated... You might choose an activity that helps with counting or spelling or another idea of your own!

1. Deciding on your activity edit

The first decision you'll need make is how your users (remember, they're 3-5 years old!) will interact with your world. Most of our environments simply involve the user clicking on different objects - but don't let that restrict you! The objects can make sounds when clicked on, or change colour, or disappear... that's up to you. You may want to run your idea past your classmates or facilitator to get additional ideas too.

2. Designing your world edit

You'll then need to create your world, importing and arranging the 3D objects that will decorate your world! Note, you can grab lots of pre-designed objects from the Alice Gallery online

3. Creating your interaction edit

Once your world is ready you can begin adding interaction through mouse or keyboard events. You can have objects that change or make noises when your users click on them, or you might allow your users to control the movement of an object using the keyboard or mouse.

4. Creating your introduction edit

It's useful for your users to see what your world is about when it first starts - just like the brief song of the singing penguins in the third tutorial that helps you to see that the penguins each sing a note! Design and create a brief animated introduction (10-30secs) for your own world that is played whenever your world first starts. This intro should help your users see how they can interact with your world.

Checklist edit

Once your world is finished, you should find that you have:

  • imported objects into your world
  • used the methods and properties of different objects within your world
  • created your own methods for some objects within your world
  • added your own events to your world so that your world reacts to user interaction
  • had some fun learning the basics of computer programming!

In addition, you should have also

  • used a variable or two in your program to count something (or add functionality in some way!)
  • used an IF-statement or two to make decisions in your program

If you were really tricky, you may have also

  • used a While-loop to repeat a few things in your program!

I hope you enjoy creating your first interactive world, and if we like what we see, we might have a development position becoming available at Kidzworks shortly!

- Janet.