Making Objects Move in Unison: Using Lists

Slides:



Advertisements
Similar presentations
Space Man Sam: Grammar Mistakes By Aleis Murphy Duke University, Under the direction of Professor Susan Rodger July 2010.
Advertisements

Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Skater World: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger May 29,
How Tall Are You? Introducing Functions By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made June 2014 by.
Scene changes By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 2008.
Skater World: Part Four By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 2009.
Lights Camera Action! Part 3: BDE Events By Deborah Nelson under the direction of Professor Susan Rodger Duke University July 2008.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Methods Tutorial: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 9, 2008.
Creating Functions Deborah Nelson Duke University Professor Susan Rodger July 22, 2008.
Alice Learning to program: Part Two by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Checking for Collisions Ellen Yuan Under the direction of Professor Susan Rodger at Duke University June 2014.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June
3–D Helium Molecule Tutorial Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008.
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Methods Tutorial: Part Two By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
By Deborah Nelson Duke University Professor Susan Rodger July 13, 2008.
Scene changes By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June
Animating Objects in Groups: Using Arrays and Lists By Ruthie Tucker under the direction of Professor Susan Rodger Summer 2008.
Lists Tutorial By Deborah Nelson Duke University Professor Susan Rodger July 13, 2008.
An Introduction to Alice (Short Version) – Extras! Yossra Hamid Under the Supervision of Professor Susan Rodger Duke University, June 2014 This is a continuation.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1,
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
The Essentials of Alice (Bunny) By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
Making Billboards By Deborah Nelson Duke University, Under the direction of Professor Susan Rodger, July 14, 2008.
1 Quiz Template: Using the ‘ask user’ functions By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 2009.
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Changing Camera Views! Part 1: Set Point of View to By Bella Onwumbiko under the direction of Professor Susan Rodger Duke University July 2013 Updates.
Skater World: Part Three By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 2009.
Skater World: Part Four By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1, 2009.
An Introduction to Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University, June 2009 Updated June 2014 by Ellen Yuan.
BDE tutorial By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 13, 2008.
Illuminating Computer Science CCIT 4-6Sep
Using Placeholders to Simplify your Methods: Learning Methods, Part 2 By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June.
The Essentials of Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University May 2009.
Making Billboards By Deborah Nelson Duke University, Under the direction of Professor Susan Rodger, July 14, 2008.
The Essentials of Alice (Bunny)
Getting Started With Alice: The Basics
Skater World: Part Four
Professor Susan Rodger
An Introduction to Alice (Short Version)
Teaching Characters to Walk: Learning Methods, Part 1
Professor Susan Rodger
Changing Camera Views! Part 1: Set Point of View to By Bella Onwumbiko
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Changing Color, Using Text Objects, and Random Selection in Alice
Making Objects Move in Unison: Using Lists
Skater World: Part Three
Making Objects Move in Unison: Using Lists
Methods Tutorial: Part Two
Making Objects Move in Unison: Using Lists
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
An Introduction to Alice
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events
How Tall Are You? Introducing Functions
Getting Started With Alice
Professor Susan Rodger
Headshots in Alice Duke University Professor Susan H. Rodger
Professor Susan Rodger
Getting Started With Alice: The Basics
Using Placeholders to Simplify your Methods: Learning Methods, Part 2
Professor Susan Rodger
Presentation transcript:

Making Objects Move in Unison: Using Lists By Deborah Nelson Duke University Professor Susan Rodger July 13, 2008 Updated June 2014 by Yossra Hamid

Overview This tutorial will teach you how to use lists. A list is a sort of holding place for a row of objects. With a list, you can make several objects do the same thing at the same time without having to write out code for each one. You can also have them do the same thing one object at a time. We will use a list to make a group of ninjas to perform some actions at the same time, and then one at a time.

Loading the World Open a new world, with any template. Save it in a directory that you can find again. After you have opened the file go into the layout mode by clicking on the Add Objects green button (toward the middle of screen). Click the more controls button. Click drop a dummy at the camera. Rename the dummy originalPosition. To leave the layout mode, click Done.

Adding the Objects Go to the Web Gallery and then to the People folder. Add four evilNinja objects to your world. Add two other people to your world. I’ve added the scientist_man and scientist_woman from the Web Gallery.

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 world in the object tree, and then click on the world’s properties tab. Click the create new variable button. Name it characters. See the screenshot on the next slide for an illustration.

Making a list (cont 1) In the gray box that pops up, select object as the type of variable. Then, check the box that is next to the words make a List. Click the new item button four times. For item0, click the down arrow next to <None> and select evilNinja. For item1, select evilNinja2. For item2, select evilNinja3. For item3, select evilNinja4. See the screenshot on the next slide for an illustration.

Making a List cont(2) Now, there is a characters list variable present at the top of the world’s properties tab.

Part 2: Writing the method Drag a For all together into world.my first method.

Writing the method (cont 1) In the drop down menu that appears, select expressions, then select the list world.characters. For all together means that all of the items in the list will perform the instructions that we will add at the same time.

Step 1: For all together Click on the item_from_characters button in the For all together statement, hold your mouse down, and drag and drop it on to the words Do nothing.

For all together (cont 1) In the drop down menu that appears, select turn to face, and then select camera. Click on more… to change the duration to 0.25 seconds. Enter in the code below by dragging and dropping the item_from_characters button twice more and selecting the move command, first up 1 meter, then down 1 meter. Make each command’s duration .25 seconds. Play your world. Your method should look like this:

Step 2: For all in order Now drag a For all in order underneath the For all together, and select expressions, then world.characters.

For all in order (cont 1) For all in order means the ninjas will perform all of the instructions that we add inside of it, 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, the item_from_characters is just a placeholder, so we cannot tell item_from_characters to turn its left leg. We will have to use a class-level built in function to turn only a part of the object.

For all in order (cont 2) First, drag item_from_characters into the For all in order and select turn, then backward, then ¼ revolution. Set the duration to .25 seconds. Click on evilNinja in the object tree. Select the functions tab and scroll down and find evilNinja’s part named key.

Step 3: Object part named key Drag that function on top of the item_from_character in your For all in order instruction.

Object part named key (cont 1) In the object tree, expand the + sign beside evilNinja to see its body part 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 spacing, and the second L must be capitalized. See the screenshot on the next slide for an illustration.

Object part named key (cont 3)

For all in order (cont 1) Drag item_from_characters on top of evilNinja in the line of code about the leftLeg. Drag item_from_characters into the For all in order again below the leftLeg command, and select turn, then right, then 1 revolution. Set the duration to .25 seconds.

For all in order (cont 2) Then drag another item_from_characters into the For all in order and select turn, then forward, then ¼ revolution. Set the duration to .25 seconds. Your For all in order code should look like this so far:

For all in order (cont 3) We need to make that last turn forward instruction for the leftLeg only. To do this, drag the function evilNinja’s part named key on top of item_from_characters in that line of code, 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 now

Step 4: Objects with different parts So far, our list only has evilNinjas in it. Add the two other people 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. See the screenshot on the next slide for an illustration.

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 this error because the world is searching for a leftLeg part to move that is not there.

Fixing the error For example, I’ve added the Samurai (from the Web gallery in the People folder). When I add him to my list and play the world, I get the following error: This is because the Samurai does not have a part named leftLeg.

Fixing the error (cont 1) In the object tree, click on the + sign beside Samurai. Double click on the body part named Lleg. Rename it leftLeg. Now play your world. Success!

How to remove an object 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. See the screenshot on the next slide for details.

Deleting an object from your list 3) Drag the item you want to delete to the trash can. This object is still in your world, but it will be removed from the 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 perform an action 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 objects to your list, because doing so will slow your world down significantly.