Alice+Tut6+Lists+and+arrays


 * ~ home ..... Getting Started ..... ||~ Tutorials and Commands ..... ||~ resources ||

Arrays and Lists

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, lists and arrays are visual objects that can be dropped into your world.

Making a list 1. Create a default world. add 5 objects that are all the same to your object list. I used goldfish. (add object is the button underneath the view of your world)

2. drag the "for all together" button onto the method editor. 3. Create "new list"

4. A white box will come up to initialize the list. add all of your goldfish into the list. do not forget to name the list, i named mine mygoldfish. The type is object. This is what it looks like after you press okay.

To have all of your goldfish do actions together, use "do in order from the bottom, and place a few actions into the bar. I chose for my goldfish to move up by .5 meters, then move right by .5 meters, then forward by 1 revolution. you can choose any of the goldfish in the list to perform the actions, because it will be changed.

Drag item_from_mygoldfish into the box that was originally 'goldfish'. repeat for each action.



This will make our school of fish perform the same actions in unison!

Now, we used for all together, if we used for all in order instead, each fish would do the actions one at a time, until all of the fish have done the action.

Lists are great for getting a group of objects to do the same thing!

Don't forget to test your code.

What if we want to code only some of the objects in our group to do something? this is where arrays come in.

drop an array visualization into your world. - go to add objects - select the folder at the end of the list titled, 'visualizations' select the 'array visualizations', it looks like a strip of concrete. Once you place this into your world, a new window will open called visualization array. add all of your goldfish to the array, and press okay.



Once you press okay, your fish will be lined up, and a new item will be added underneath all of your goldfish objects.

Click on your “Array Visualization” and then “properties”. Set “Is showing to False” to hide your Array Visualization so that the chickens do not look like they are standing on anything.However, the Array is still there and functional

When we put all of these elements together you can see how Lists and Arrays can be used interchangeably to animate your Alice world. The ‘For all together’ command in Lists allows you to animate a group of objects to do something together. The ‘For all in order’ command in Lists allows you to animate the whole group of objects to do the same thing, but one at a time. The Array allows you to have a group of objects do different things.