Please help! I'm trying to spawn 5 balls one by one from the sky and have them disappear as soon as they hit the ground or when they hit another user-controlled object that's on the ground. The good thing is that I can spawn the balls successfully as intended, but when they hit the ground (or the other user-controlled object on the ground), they don't disappear. I've been going through a ton of sample code since the past 2 days but I can't figure out how to do it. The game does run, but the debug terminal gives me an error saying: runtime error - attempt to index global 'self' . Here's the source code:
local randomBall = function()
ball = display.newImage( "hardball.png" )
ball.x = math.random (30, 450); ball.y = -20
physics.addBody( ball, { density=2.9, friction=0.5, bounce=0.7, radius=24 } )
local function whenHit (event)
if(event.phase == "began") then
self:removeSelf()
end
end
ball:addEventListener("collision", whenHit)
end
timer.performWithDelay( 500, randomBall, 5 )
self. Look at this example. – bummzack Aug 19 '11 at 7:27