Event.other is nil in onCollision after resuming a scene using the storyboard library [CORONA sdk]

I got a weird bug with the Corona SDK related to collision detection and lib.

Here is my listener onCollision:

local function onBottomBorderCollision( event )    
    if (event.other.isBall) then
        local index = table.indexOf( ballArray, other )
        table.remove( ballArray, index )
        event.other:removeSelf( )
        event.other = nil
        updateLife(false)
        updateScore(false)
    end
end

This works well on the first start, but after returning to the menu screen (using storyboard.goToScene("menu"))and re-playing the game, now this listener will raise the following error every time one of my balls gets to the bottom border:

attempt to index other field (nil value)

I create the correct listeners in scene:onEnterScene(scene), so it is not associated with them, moreover, this other listener never generates an error:

local function onPlayerCollision( event )


    if(event.other.isBall) then
       xVel, yVel = event.other:getLinearVelocity( )
       event.other:setLinearVelocity( event.other.XLinearVelocity, yVel )

   end

end

I'm stuck right now ... please help!

+4
2

, - // , .

attempt to index field "other"(a nil value)

, object/it /, . , , , .


onBottomBorderCollision . enterFrame, . , :

Runtime:removeEventListener("enterFrame",onBottomBorderCollision)

: , . , :

function actualSceneChange()
     physics.stop() -- stop physics here
     -- call scene chage
     director:changeScene("menuPageName") -- call your scene change method
end

function initiatingSceneChange()
    physics.pause() -- pause physics here
    -- stop unwanted event listeners
    Runtime:removeEventListener("enterFrame",onBottomBorderCollision) 

    if(timer_1)then timer.cancel(timer_1) end    -- stop all your timers like this.
    if(trans_1)then transition.cancel(trans) end -- stop all your transitions like this.

    timer.performWithDelay(1000,actualSceneChange,1)
end
+3

, , . , . , CreateScene, , .

, , . Storyboard.removeScene.

"EnterScene" menu.lua , . . - :

storyboard.removeScene("game")

destroyScene purgeScene

0

Source: https://habr.com/ru/post/1542770/


All Articles