Need help OBJECT:removeSelf()

I have a variable defined as…

local layerBack={file,obj}

and this works fine - layerBack.obj:removeSelf()

but this…

local layerMain={file={},obj={},xpos={},width={},ypos={},height={},flip={}}

with the same concept - layerMain.obj[1]:removeSelf()

results in an error…
attempt to call method ‘removeSelf’ (a nil value)

Any thoughts as to what I’m doing wrong and how to clean up memory for my layerMain table?

Thanks. :slight_smile: [import]uid: 10789 topic_id: 8923 reply_id: 308923[/import]

Are you sure there’s a display object assigned to layerMain[1].obj ?

You can do this:

[blockcode]
if layerMain[1].obj.removeSelf then
layerMain[1].obj.removeSelf()
layerMain[1].obj = nil
end
[/blockcode]

That should take care of the error. You can also do a for loop and iterate through all the keys of layerMain to do that check and call removeSelf() on everything that has that method available (display objects).

Hope that helps! [import]uid: 52430 topic_id: 8923 reply_id: 32586[/import]

Thank you. :slight_smile: [import]uid: 10789 topic_id: 8923 reply_id: 32661[/import]