Understanding Parameters in Alice - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Understanding Parameters in Alice

Description:

Click on the create new parameter button in the upper right hand corner of your method editor. ... Name the parameter whichAnimal. ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 9
Provided by: Jen6
Category:

less

Transcript and Presenter's Notes

Title: Understanding Parameters in Alice


1
Understanding Parameters in Alice
2
Step 1 The Purpose of Parameters
Parameters can be used as placeholders in Alice
that can hold different pieces of information
each time a method is used. We will use them in
this tutorial to write just ONE method that can
be used by multiple objects. So, download the
world that goes along with this tutorial. You
will see four animals standing in a row.
3
Step 2 Writing the Method
First well write the method that we will use for
all of our animals. We want to make them turn
around once and then jump up and down at
different heights. So first create a new world
method called animalMove. In this method, add a
command that tells one of the animals to turn one
revolution to the right, move up one meter, then
down one meter. It doesnt matter which animal
right now.
4
Step 3 Creating an Object Parameter
Now its time to create our parameter. Click on
the create new parameter button in the upper
right hand corner of your method editor.
Now, wherever in your code you tell an animal to
do something, drag the whichAnimal parameter over
the animals name, and drop it there. Your code
will look like the method editor on the next
page.
On the menu that pops up, select Object. Name the
parameter whichAnimal.
5
Your code should look like this
6
Step 4 Creating a Number Parameter
Then drag the howHigh parameter over the parts of
your code that say 1 meter, and drop it there.
Your code will look like this
Now we want to make our code even MORE flexible.
We want to make it so that each of our animals
can jump different lengths in the air. Click the
create new parameter button, and this time create
a number parameter called howHigh.
7
Step 5 Finishing Up
Each time you drag the method over, select a
different animal and a different length for that
animal to jump. At the end, your code should have
each animal turn around, and then jump up a
different length. An example for what your code
could look like is on the next page.
Now drag animal Move into world.my first method
four times. Each time you drag it in, a pop-up
menu will appear so you can choose what you want
your parameters to be. It will look like this
8
Now your world is complete. Congratulations on
mastering parameters! When using parameters in
the future, remember that if you want to pass an
object into a parameter, it has to fit the method
that it is in. For example, if a method tells an
object to turn its arm, and you pass an object
into an object parameter that doesnt HAVE an
arm, you will get into big trouble. Parameters
are wonderful things, but must be wielded very
carefully.
Write a Comment
User Comments (0)
About PowerShow.com