We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › understanding oop
Page Index Toggle Pages: 1
understanding oop (Read 469 times)
understanding oop
Apr 25th, 2006, 5:59am
 
hi, i come from lingo , im trying to understand oop in processing...
i asked some time ago something about this , but i didnt understand it very well....
i have a code that creates objects in time(real world time).. for example, my class creates a dot each 10 seconds and animates it .... i want that after 30 seconds the objects become destroyed.... im using vector to store all my objects. my question is if i delete the object in my vector does the object becomes destroyed? and my second question is how can i delete a object from my vector? or how can i make that my object auto delete itself from the vector?

in lingo i can put this on my parent script (for autodestroying objects):
on new me, f
me.myframe = f
return me
end new

on stepFrame me
if the frame <> me.myframe
deleteOne the actorList, me
end if

--


is there any way of making something like this in processing?


many thanx for the help




Re: understanding oop
Reply #1 - Apr 25th, 2006, 12:49pm
 
Hi punchik,
I also began programming with lingo and I also struggled initially with the differences in oop in java

In java it's just that you have to set up your own class or methods to manage your objects whereas in lingo the native actorlist and stepframe structure did it all for you.

I am too new to java to assure you of absolute best practice but rather than creating each object with it's own run method (or stepframe) and letting it deal with it's own deletion I use a kind of manager class with a single, central run method.

This way if you have multiple objects that need to be animated or operated on in some way you can simply store references to these in an array within the manager object and iterate through this array in the manager's run method.

To remove a specific object you of couse then need to delete it from the manager object array. This can be done by iterating through the object array until you find the matching object reference and then by performing some array manipulation to remove it's entry from the array.

hope that helps?

james

Re: understanding oop
Reply #2 - Apr 26th, 2006, 5:00am
 
ok thanks for the reply... but can you say me how can i delete my object or object reference from my vector list?
is there any special command for doing this???

many thanx


punchik
Re: understanding oop
Reply #3 - Apr 26th, 2006, 10:49am
 
If it's a Java Vector you're using you can do:

MyVector.remove(4); //if 4 is the index of the one you want to remove.

See: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html for all the options.
Page Index Toggle Pages: 1