Detecting wether a reference to an object is still active (ie not destroyed) (pointers in LUA?)

?

function DestroyObj(other)     -- NOTE! The object may already be destroyed at this point but the copy of the object stored in the other function is still there     -- how can i tell if the table in event.other is not destroyed     -- For example in C++ i would use a pointer but ... this is LUA :(     -- i thought display.remove(other) would return false if it didnt work but it doesnt end function onCollision(self,event)     self.otherobj[#self.nextobjecttodestroy+1] = event.other     end

You can do a test like:

if object and if object.removeSelf then

   – the object is probably not been removed

end

The first test will be true if it’s not nil.  The next will be true if it’s not nil and it has a member called removeSelf, which all display objects should have.

Rob

thanks for the help in the end i use that code in a different place because it doesnt quite do what i want. if anyone is interested i ended up placing all destroyed objects in a static array in my class( ie placed outside the constructor) and then looping through that array to check wether that obj has already been destroyed, not elegant but it does the job

You can do a test like:

if object and if object.removeSelf then

   – the object is probably not been removed

end

The first test will be true if it’s not nil.  The next will be true if it’s not nil and it has a member called removeSelf, which all display objects should have.

Rob

thanks for the help in the end i use that code in a different place because it doesnt quite do what i want. if anyone is interested i ended up placing all destroyed objects in a static array in my class( ie placed outside the constructor) and then looping through that array to check wether that obj has already been destroyed, not elegant but it does the job