Visual Programing - TutorialforArraysandLists
Visual Programing - TutorialforArraysandLists
and Lists
By Ruthie Tucker
Description
This presentation will cover the basics of using
Arrays and Lists in an Alice world
It uses a set of chickens on a farm
Prerequisites
Everything
This is the last tutorial you should do in this course
The Characters
Side Note
Glitch in Alice
Alice cannot compute your world if you put the
same objects in a “List Visualization” as an “Array
Visualization”.
I will demonstrate how to use the “List
Visualization” later, but for now we are just going
to make a regular list.
However, you can use a list without the actual
ListVisualization, if you also want to use an
“Array” in your world.
Getting Started
What is a List?
A list is simply a way to
organize information.
What is an Array?
An Array is a structure for
collecting and organizing
objects or information of
the same type into a group.
In Alice Arrays and Lists
are also visual objects
which can be dropped into
your world
Cinderella Conducts
We are going to make the world you just watched and use
Lists and Arrays to make the chickens dance
This is the code to make Cinderella conduct while the
chickens dance. If you want to add this to your world you
can code it now and save it. We will use it at the end.
Making a List
Create a world level
method named
“ChickenMove”
Drag the “For all
Together” Button onto
the method editor
Select “Create new list”
Lists
Name it
“ChickDanceTogether”,
select “object” as the type.
A white box will come up
that says “initialize list”.
Click new item until all
the chickens are in your
list. The first item starts at
0. Keep your chickens in
order.
Lists
Now go to Array
Visualizations, properties, and
drag the “elements” tab down
to your parameter.
Select 0, repeat this step for
each chicken in your Array
Complete Turn to Face Code
Note that each element in the Array is coded separately but
they are all doing the same thing. Now let’s get them to do
different things.
Getting Chickens to do Different
Things
Note that we only selected chickens
To get the chickens to move up 0, 2 and 4 to perform this task.
and down at different times you After making the even number
will follow the same steps that
chickens move up and down, add
you just performed with" Turn to code to make the odd number move,
Face” in the Cinderella slide. separately.
See the code below
Arrays Continued
This is the beauty of the Array
Once you have finished It allows you to only move
plugging in the Array your selected objects in your Array
code should look like this Whereas with the List you
Note that only chickens 0, 2, must move everything
and 4 are going to move.
Arrays
This is the visual
Note how Chickens 0, 2
and 4 are moving down
while chickens 1, 3, and
5 are moving up.
You can program each
chicken individually or
in any number you want
to
Putting it all together
For the Final construction I created a BDE event and
did the same trick that was used in the vehicle
tutorial. Put an invisible bunny in the world and have
him change colors. While he is one color Cinderella
conducts, while he is a separate color she does not.
The bunny will turn one color while the chickens
begin to dance, this will trigger Cinderella to start
conducting. When the chickens finish, the bunny will
turn a different color, which will signal Cinderella to
stop.
Final construction