Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Identical click behavior for a group of objects
Old
ohioboater
Junior Member
 
Status: Offline
Posts: 5
Join Date: Apr 2014
Default Identical click behavior for a group of objects - 04-25-2014, 06:01 PM

Apologies if this is an obvious question. My son has a world with 6 buildings in it. For 5 of those buildings, if the user clicks on the building, the world should display a message that the building is locked. He knows how to do this with a series of nested if/else statements, but is there a more elegant way to do this? His idea was to have a list of buildings, and when an object is clicked, check to see if that object is a member of that list. But that doesn't seem to be the way lists/arrays work in Alice. But then I'm learning this along with him, so I could very well be missing something.

This is in Alice 2. We've been using the Duke tutorials and the Dann/Cooper/Pausch textbook.
   
Reply With Quote
Old
sfunk
Senior Member
 
sfunk's Avatar
 
Status: Offline
Posts: 1,112
Join Date: Mar 2011
Location: I don't know
Default 04-25-2014, 07:24 PM

A list is exactly what you want to use. make a list of the buildings that are locked. then use the for all function in an if statement and make sure that list is in the function.


If you are stuck on a project, check out the tutorials I made here at this link:

http://alice.org/community/showthread.php?p=36778#post36778

There are lots of tutorials on it so far, including some youtube videos, check it out

Or..

Go to my youtube channel to check out my alice 2.2 tutorials I have there..

http://www.youtube.com/user/sfunk1992?feature=mhsn
   
Reply With Quote
Thank you
Old
ohioboater
Junior Member
 
Status: Offline
Posts: 5
Join Date: Apr 2014
Thumbs up Thank you - 04-29-2014, 07:44 PM

Cool, thank you for the reply.
   
Reply With Quote
You're on your way
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default You're on your way - 04-29-2014, 10:26 PM

Your son is correct about the use of the lists.
One of the possible events is the "When mouse clicked on anything" do "something".

First, create the list.

Next, create a method that will check the list, and add an object parameter.

Next, create the event and replace "Nothing" with the name of the method. This will pass the "what was clicked" object as the parameter.

Now, pull in a "for all in order" into the method, and use an If to check the parameter object against each member, and says "locked" if a match is found.

Same code will work for any size list.

Last edited by MrMoke; 04-30-2014 at 08:04 AM.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2018, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.