How to tell if an object exists?

Okay I noticed that when you remove and image using

obj:removeSelf()

and you check it using

if(obj) then

    --Do something

end

it will always return true until you set obj to nil. Is there a way to check if the obj has been removed but not set to nil? I have an instance where I need to remove the image but not set it to nil but I also need to check if it exists.

Thanks

RemoveSelf() does not remove object completely. It only frees part of object containing data of for eg. image. So after removeSelf you still have some barebone data in form of plain table - that’s why you must also nil it to free memory completely. If you want to differentiate if it’s full object (display object) or just barebone table then check if it contains methods of display object, as obj.removeSelf. Barebone table will not have this function.

Makes sense now thanks for that insight. I almost always = it to nil after removing it but in this case it would cause more of an issue then not.

If you need to test if an object is currently in / or has already been removed from the display, you can check as so

[lua]

    if( object.removeSelf ~= nil ) then    – Check if it’s still added to the display…

        object.removeSelf()

        print(" – removing object from display")

    else

        print(" – object was already removed from display")

    end

[/lua]

RemoveSelf() does not remove object completely. It only frees part of object containing data of for eg. image. So after removeSelf you still have some barebone data in form of plain table - that’s why you must also nil it to free memory completely. If you want to differentiate if it’s full object (display object) or just barebone table then check if it contains methods of display object, as obj.removeSelf. Barebone table will not have this function.

Makes sense now thanks for that insight. I almost always = it to nil after removing it but in this case it would cause more of an issue then not.

If you need to test if an object is currently in / or has already been removed from the display, you can check as so

[lua]

    if( object.removeSelf ~= nil ) then    – Check if it’s still added to the display…

        object.removeSelf()

        print(" – removing object from display")

    else

        print(" – object was already removed from display")

    end

[/lua]