[Resolved] How to figure out that object was already removed?

For example I have such code:

local obj = display.display.newCircle( 0, 0, 50 )
obj:removeSelf()
obj:removeSelf()

on the third line I will have an error that object already was removed. do I have any way to figure out does object was removed, can I write something like:
if obj.parent ~= nil then
obj:removeSelf()
end

as I read in docs: “all properties relating to display object are removed” can I check some of it to be sure that object was removed already? [import]uid: 70928 topic_id: 28333 reply_id: 328333[/import]

obj:removeSelf() removes the display object. The proper method of deletion is usually:

myobject:removeSelf() myobject = nil

So if you deleted that way you could later check to see if it was deleted by using

if myobject then -- delete object else -- its already deleted end

Saying “if myobject” is a shortcut for saying “if myobject == true”. In Lua a variable is true if it has any content assigned to it that is not false, ie:

local table = { 1,2 } -- true local table = false -- false local table -- nil

Does that help? [import]uid: 41884 topic_id: 28333 reply_id: 114472[/import]

Use this method instead:

[lua]display.remove( myObject)
myObject = nil[/lua]

As far as I’m aware, this method first checks to make sure the object isn’t already nil before removing the object. If it is already nil, this method will handle it accordingly and so will never return an error. It’s a safer way to remove display objects in Corona. [import]uid: 74503 topic_id: 28333 reply_id: 114478[/import]

Ah! Yeah, that is definitely the better option. I forgot the exact command and thought I was imagining it… [import]uid: 41884 topic_id: 28333 reply_id: 114485[/import]

I already new about this technique, but it is not answer on my question, I have some objects which contain sprites and other display objects, and they are in couple display group, and I wanted to do something like this:

for n,e in self.sprites do  
 if e and e.removeSelf then  
 e:removeSelf()  
 e = nil  
 end  
end  

but this code fails when e was in group which is already removed, as I understand display group calls removeSelf() for all items which it contains.
Thus I want to add “if” to check does object was already removed and I do not have to call removeSelf.
Something like this:

for n,e in self.sprites do  
 if e and e.removeSelf then  
 if not "e was removed earlier or group with e was removed" then  
 e:removeSelf()  
 end  
 e = nil  
 end  
end  

[import]uid: 70928 topic_id: 28333 reply_id: 115172[/import]