Hi everyone, I’ve encountered an error when I was running my code:bad argument#-1 to ‘_listener’(Proxy expected, got nil)…in function ‘_listener’…<?:141>…<?:218>
This is the first time I’ve encountered this error and I believe its related to the collision function I’ve been working on.
function scene:createScene()
local group = self.view
…
function shot:touch(event)
if(event.phase == ‘ended’) then
Runtime:removeEventListener(‘enterFrame’, charge)
cannon.isVisible = true
cannon.rotation = 0
cannonBall = display.newImage(‘cannon ball.png’, 84, 220)
physics.addBody(cannonBall, {density = 1, friction = 0, bounce = 0})
group:insert(cannonBall)-----------------------> this is line 141
print (‘shot’)
– Shoot cannon ball
cannonBall:applyLinearImpulse(3, impulse, cannonBall.x, cannonBall.y )
–Collision listener
print(‘event listener’)
cannonBall:addEventListener (‘collision’, ballCollision)
end
end
function charge()
local degreesPerFrame = 1
cannon.rotation = cannon.rotation - degreesPerFrame
impulse=impulse-0.2
if(cannon.rotation < -46) then
cannon.rotation = -46
impulse = -3.2
print(‘Charge’)
end
end
function ballCollision(event)
if (event.other == balloons[3]) then
scene.updateScore()
print(‘Ball is colliding’)
timer.performWithDelay(1, event.target.removeSelf, event.target)
timer.performWithDelay(1, event.other.removeSelf, event.target)
balloonText3.isVisible = false – this is ok: not involved in collision
audio.play(pop)
end
end
end
…
return scene --------> this is line 218