Alice Community  

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

Reply
 
Thread Tools Display Modes
Call custom method from objects in list
Old
dragnet
Member
 
Status: Offline
Posts: 38
Join Date: Jan 2010
Default Call custom method from objects in list - 03-18-2010, 02:02 PM

I've looked though examples and also through the text books. Can't seem to find a way to call custom methods whe iterating through an object list. For example I want to call a swim method for each fish in a list I've created 'allFish'. When I create a 'For all together' loop to iterate through my array 'allFish', the only options that show up are method calls to the built in object methods, no custom methods are listed. Is there a way to change this?

My only other option is to create a world method that accepts an object and makes it move as I want. Then I can cycle through my list and pass each object to the world method. It works but is not what I would consider as clean of a coding technique.

Thanks.
   
Reply With Quote
Old
dragnet
Member
 
Status: Offline
Posts: 38
Join Date: Jan 2010
Default 03-19-2010, 12:18 PM

I've played some more. Pretty sure it can't be done. You can kind of wiggle a similar effect using the 'part named' function, but not exactly what I want.

Would be really nice if you could set an object property using the 'variable name variableName of type' along with a itemInList object. All I can seem to do is get property values out of a generic object and turn them into a string using the 'what as string' function in conjunction with the above 'variable name' function.

Is there a way to code directly in the editor? If you know it will work can you directly enter a line of code like

itemInList.swim(howMuch);

in a For all together loop that cycles through a list?

Thanks.
   
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 03-19-2010, 03:18 PM

Yeah it can't be done the way you'd want it to, but you could try calling the same method in the For All... statement with an object parameter, use the "item from[listname]" value as the object parameter, then have either a bunch of if/else ifs determine what to do with the object in the method, or use that "part named" function like you said to have them all do similar moves.


(')>
   
Reply With Quote
Old
dragnet
Member
 
Status: Offline
Posts: 38
Join Date: Jan 2010
Default 03-19-2010, 03:24 PM

Thanks for the reply.

After reading some other posts (Which I should of done first) I came to the same conclusion. It can't be done. Would be great if Alice 3 incorporates casting as well as true inheritence and polymorphism. As a Comp Sci student with a couple of years of OO programming experience, I feel I almost need to unlearn techniques to use Alice effectively. I can't say this is a drawback to using Alice, just a learning curve. I haven't found anything I can't do in Alice yet. It's just not always as intuitve as I would like.
   
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.