Best way to Check for Removed Object

What is the best way to check for a removed object? I have been pretty careful and my method works pretty well most of the time. Linearly, my method works 10 times out of 10, but sometime if a lot is going on, the object would pass my test in one function, get deleted by another function, and then try to be deleted in the original function. This throws massive errors in corona and has me thinking of crazy what if cases that start to bloat my code.

Here's my method:

1
2
3
4
5
if obj then 
    if obj.x then
        obj:removeSelf()
    end
end

i use "display.remove(object)" function, its basically the same as yours

What happens if the object is already removed?

this will not get you any errors

1
2
3
4
5
6
7
8
local button = display.newRect(100,100,50,50)
 
 
local function rem1()
        display.remove(button)
end
 
timer.performWithDelay(1000, rem1,10)

What really??? Soo many useless if statements :(.

Thanks...now I have to go replace about a hundred of these lol.

tell me about it, i didnt knew about this function until some days ago)
good luck then

views:1507 update:2011/12/29 9:44:01
corona forums © 2003-2011