Tutorial: Lists
By Deborah Nelson
Duke University, July 13, 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
Open a new world, with the template of your choosing.
Save it in a directory that you can find again. 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.
Adding Objects
- Go to the gallery and add four evilNinjas to your world (from the People folder)
- Add two other people to your world.I’ve added the scientist-man and scientist-woman
Part 1: Making a list
- We will use a list to make all four of the ninjas jump up and down together and then kick and spin one at a time
.
- Click on the world in the object tree and on the properties tab
- Click create new variable. Name it ‘characters’
- Select object as the type
- Check the box make a List
- Click the new item button four times
- For item0 select evilNinja
- For item1 select evilNinja2
- For item2 select evilNinja3
- For item3 select evilNinja4
- Now, there is a characters list variable at the top of the world properties tab
Part 2: Writing the method
- Drag for all together into world.my first method
- In the drop down menu, select expressions, then select the list world.characters
- For all together means that all of the items in the list will perform the instructions at
the same time.
Step 1: For all together:
- Click on item_from_characters and drag it on top of the Do nothing
- In the drop down menu, select turn to face and then select camera
- Click on more to change the duration to 0.25
- Drag item_from_characters again and select the move up and move down instructions.
- Play your world. Your method should look like this:
Step 2: For all in order:
- Now drag for all in order underneath the for all together and select expressions, then
world.characters
- For all in order means the ninjas will perform all of the instructions, one right after the other
(in the order that they were added to the list)
- We want the ninjas to each turn their left leg and spin one at a time.
- However, item_from_characters does not have any parts
- We will have to use a class level built in function to turn just a part.
- First, drag item_from_characters into the for all in order and select turn backward 1/4
- Click on evilNinja in the object tree.
- Select the functions tab and scroll down to evilNinja’s part named key
- Drag that function on top of the item_from_character in your instruction
Step 3: Object part named key:
- Drag that function on top of the item_from_character in your instruction
- In the object tree, click on the + beside evilNinja to see that it’s body part is named leftLeg
- In the turn backward instruction, click on the box and type leftLeg with the same capitalization and spacing as it appears in the object
tree. No blank spacers, and the second L must be a capital letter
- Drag item_from_characters on top of evilNinja
- Drag item_from_characters into the for all in order again and select turn right 1 revolution
- Then drag item_from_characters again and select turn forward ¼. Your loop should look like this so far:
- That last instruction should be for the leftLeg only.
- So drag the function evilNinja’s part named key on top of the item_from_characters and type in leftLeg again.
- Drag item_from_characters on top of evilNinja in the part named key
The complete method
- Here is the complete method. Don’t forget to comment your code
- Play your world
- Below is a screenshot of the world playing
Step 3: Object part named key:
- So far, our list only has evilNinjas in it. Add the other objects to the list:
- Click on world in the object tree
- Go to the properties tab and click on the box beside characters
- Click on new item and select the object you want to add
Warning
- Play your world.
If you did not use the same objects as this demonstration, you may get an error highlighting the parts named function.
Adding the scientist-man and scientist-woman to the list only works because they both have leftLeg as the label for one of their body parts
If your character does not have a part named leftLeg you get the error
Fixing the Error
- For example, I’ve added the Samurai (from the web gallery People folder).
- When I add him to my list and play the world, I get the following error:
- Because the Samurai does not have a part named leftLeg
- In the object tree, click on the + beside Samurai
- Double click on the body part named Lleg
- Rename it leftLeg
- Now play your world:
- Success!
How to remove an object from your list
- To delete an object from your list:
- Click on world in the object tree
- Go to the “properties” tab and click on the box beside Characters
- Drag the item you want to delete to the trash can.
- Notice, the object has not been deleted from your world,just from your list
Recap
- Lists are useful for having multiple characters perform the same set of actions.
- For all together means everything in the list will perform at the same time
- For all in order means everything in the list will happen one right after the other
- To make the sub parts of an object move, use the function part named key. But make sure all of the characters
have the same parts labeled the same way
- WARNING: Do not add too many items to your list. Doing so will slow your world down
significantly