WARNING: Attempting to set property(1) with nil - how do I fix this.

in my game I have some code to clean up all the display objects that I don’t need anymore when switching from game.lua to over.lua

I get a bunch of warnings in the terminal and I am wandering how to fix this.

WARNING: Attempting to set property(9) with nil
WARNING: Attempting to set property(8) with nil
WARNING: Attempting to set property(7) with nil
WARNING: Attempting to set property(6) with nil
WARNING: Attempting to set property(5) with nil
WARNING: Attempting to set property(4) with nil
WARNING: Attempting to set property(3) with nil
WARNING: Attempting to set property(2) with nil
WARNING: Attempting to set property(1) with nil

code looks something like this

[lua]local function gameOverCleanup( )

Runtime:removeEventListener(“postCollision”, onCollision)
Runtime:removeEventListener( “enterFrame”, onEnter )

background:removeSelf()
background = nil
player:removeSelf()
player = nil
dpad:removeSelf()
dpad = nil
dpad_light:removeSelf()
dpad_light = nil
bn_thrust:removeSelf()
bn_thrust = nil
bn_fire:removeSelf()
bn_fire = nil
score_text:removeSelf()
score_text = nil

while missles.numChildren > 0 do
missles[missles.numChildren]:removeSelf()
missles[missles.numChildren] = nil
end

missles = nil

while astroid_group.numChildren > 0 do
astroid_group[astroid_group.numChildren]:removeSelf()
astroid_group[astroid_group.numChildren] = nil
end

astroid_group = nil
lives_group = nil

Runtime:addEventListener(“enterFrame”, gameEnterFrameHandler)
changeScreen(“over_screen”)
callUnload = true
end

function unloadMe( )
collectgarbage(“collect”)
end[/lua] [import]uid: 6636 topic_id: 3538 reply_id: 303538[/import]

i dont think you need to do that. i believe “:removeSelf()” does it for you

what happens if you print that value tostring( astroid_group[astroid_group.numChildren]) after the removeSelf
[import]uid: 6645 topic_id: 3538 reply_id: 10675[/import]

I get the following
table: 0x37eb80
table: 0x37e8d0
table: 0x37e620
table: 0x37e350
table: 0x37e0a0
table: 0x37de00
table: 0x37db10
nil

and then I get the Warnings again

I also tried removing all the = nil statements and I get the same result

[import]uid: 6636 topic_id: 3538 reply_id: 10676[/import]

does your array get smaller ie print(#myArray) when you set one of it’s items to nil?

or does it stay the same size but with each item being nil?
[import]uid: 6645 topic_id: 3538 reply_id: 10678[/import]