Collision bug?

I have the function onCollision sometimes at the second “if” when the bottle touches the object “inside” which is a simple rectangle on phase “began” the level increases for 2 is this a bug?

function onCollision(event) if (event.phase == "began") then local obj1 = event.object1 local obj2 = event.object2 if (obj1.myName == "bottle") and ( obj2.myName == "inside" ) or (obj2.myName == "bottle") and ( obj1.myName == "inside" ) then transition.to(bottle,{bodyType = "static",time=0,x = math.random(140,230),y=0 ,rotation= math.random( -40,40 )}) audio.play( insidew ) if (barrelTime \> 1000) then barrelTime = barrelTime - 33 end level = level + 1 elseif (obj1.myName == "bottle") and ( obj2.myName == "barrel" ) or (obj2.myName == "bottle") and ( obj1.myName == "barrel" ) then audio.play( barrelSound ) elseif(obj1.myName == "bottle") and ( obj2.myName == "outside" ) or (obj2.myName == "bottle") and ( obj1.myName == "outside" ) then audio.play( outside ) gameOver = "Game Over!".." \nYour score is :".. maxscore overText = display.newText(uiGroup, gameOver, display.contentCenterX, 150, native.systemFont, 40 ) overText:setFillColor( 0, 0, 0 ) timer.performWithDelay( 1000, transition.cancel("barrelmovement")) timer.performWithDelay( 2000, endGame ) end levelText.text = level maxscore = level end end Runtime:addEventListener("collision", onCollision)

I use the outline graphics for the bottle and rectangle for the “inside”

I’ve hit a similar problem which i think is a bug. I have a variable increment inside the began phase of a collision event. Something like: score = score + 1 Intermittently the score gets incremented twice for a single collision event.

Have to say I don’t really follow your code as it’s not particularly clean. But I would think that the collision is being registered twice, hence the double increment. This is because your collision listener never returns a value, which means it returns false by default. Any listener function which returns false is indicating to Corona that it has not handle the event and so the event gets passed to the next listening object. As you have probably attached this listener to two objects, they are both handling it and level is being incremented twice.

What you need to do, any time a listener of any event correctly handles an event, is return true. That way the event will not get passed to the next listener.

I’ve hit a similar problem which i think is a bug. I have a variable increment inside the began phase of a collision event. Something like: score = score + 1 Intermittently the score gets incremented twice for a single collision event.

Have to say I don’t really follow your code as it’s not particularly clean. But I would think that the collision is being registered twice, hence the double increment. This is because your collision listener never returns a value, which means it returns false by default. Any listener function which returns false is indicating to Corona that it has not handle the event and so the event gets passed to the next listening object. As you have probably attached this listener to two objects, they are both handling it and level is being incremented twice.

What you need to do, any time a listener of any event correctly handles an event, is return true. That way the event will not get passed to the next listener.