Alice Community  

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

Reply
 
Thread Tools Display Modes
Is there a way to access an objects custom methods when referenced via a list/array
Old
louisk
Junior Member
 
Status: Offline
Posts: 3
Join Date: Jul 2012
Location: Bellevue, WA
Default Is there a way to access an objects custom methods when referenced via a list/array - 07-23-2012, 10:25 AM

If I create an array or list with several objects, all of which have a private method, is there a way to call those private methods by referencing the list/array variable?

The example would be:

I have a list of 6 different fish objects.
Each has a Swim method (and in this case, the swim method is slightly different for each fish).

I would want to do a:
All Together or All one at a time
swim... where I call the swim method of each object in the list/array by referencing the array/list itself, not the specific instance of the object.

listvar[1].swim not fish1.swim


Is this possible?

Last edited by louisk; 07-23-2012 at 10:26 AM. Reason: adding email notification
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 07-23-2012, 11:15 AM

There are a few highly inefficient workarounds, but no built-in way to do it.

I'd recommend simplifying the custom methods, if possible, to allow for the passing of parameter objects as the subjects of the method. That way, you'd have fewer methods and would require only the naming of an object, which is easily achieved through the use of variables and events.


(')>
   
Reply With Quote
Old
louisk
Junior Member
 
Status: Offline
Posts: 3
Join Date: Jul 2012
Location: Bellevue, WA
Default 07-23-2012, 11:18 AM

Yeah... thanks... I was hoping there was a way to use an array or list variable to access the custom methods of the objects inside the array/list... but what I am hearing from you (and what I have discovered myself) is that doesn't seem to be possible. Oh well...
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 07-23-2012, 02:53 PM

If you need some help with your world, you can post it and we can possibly help you implement something similar to what you want.


(')>
   
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 ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.