Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Call custom method from objects in list (http://www.alice.org/community/showthread.php?t=4096)

dragnet 03-18-2010 01:02 PM

Call custom method from objects in list
 
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.

dragnet 03-19-2010 11:18 AM

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.

x2495iiii 03-19-2010 02: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.

dragnet 03-19-2010 02: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.


All times are GMT -5. The time now is 05:31 PM.

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