Listeners Not Triggering

Hi, 

I’m creating a simple game for Corona SDK (iPad only). At some point I got 99 red balloons floating in the alien sky, and you are supposed to touch them in order to get it away for good. The first 35 or so balloons are created correctly each one pointing to a common event listener to detect touch. I don’t know why, but 36th balloon up to 99th does not triggers the event listener. Same loop, no special testings,  no nothing. Here is the balloon creation code:

function scriptReleasingBalloonsActTwo()

   alienGroup.x = alienGroup.x - 7

   alienGroup.y =  10 * cos( oldY ) + (display.contentCenterY + (alienGroup.contentHeight / 2) + oldY / 5)

   oldY = oldY + 0.10

   alienGroup.setReferencePoint(alienGroup, display.CenterLeftReferencePoint)

   if alienGroup.x <= (alienGroup.width + 20) * -1  then

      scriptDirectorFlag = false

      scriptCurrentAct = 1

      scriptReleaseBalloonsFlag = false

      return

   end

   local aNumber = random(1,100)

   if aNumber > 15 and aNumber < 90

      and totalBalloons < 100

      and (alienGroup.x + (alienGroup.width/2)) < display.contentWidth then

      totalBalloons = totalBalloons + 1

      extraChallenge = “balloons”

      local newBalloon = sprite.newSprite( balloonSpriteSet )

      physics.addBody( newBalloon, { density=1, friction=0, bounce=.9, radius=30 } )

      newBalloon.xVariation = (random(1,5) / 10) * -1

      if totalBalloons > 70 then

         aNumber = 30

      end

      if not yellowBalloonReleased and aNumber == 30 and alienGroup.x < display.contentCenterX then

         newBalloon:prepare(“yellowBalloon”)

         yellowBalloonReleased = true

         newBalloon:setLinearVelocity( 0, -75 )

         newBalloon.yVariation = random(10,15)

      else

         newBalloon:prepare(“redBalloon”)

         newBalloon:setLinearVelocity( 0, -15 )

         newBalloon.yVariation = random(5,15) / 10

      end

      newBalloon:play()

      newBalloon.touched = false

      newBalloon.x = alienGroup.x + alienGroup.width / 2

      newBalloon.lifeTime = random(45, 100)

      newBalloon.life = 0

      newBalloon.midTime = modf(newBalloon.lifeTime * .6 )

      newBalloon.y = alienGroup.y

      newBalloon.xScale = .1

      newBalloon.yScale = .1

      newBalloon.active = true

      newBalloon.oldX = newBalloon.x

      newBalloon.setReferencePoint(newBalloon, display.CenterLeftReferencePoint)

      newBalloon.touch = onBalloonTouch

      newBalloon:addEventListener(“touch”, newBalloon)

      table.insert(balloons, newBalloon)

      newBalloon.id = #balloons

      local finalY = alienGroup.y - (alienGroup.contentHeight / 2)

      table.insert(transitionStash,

      transition.to(newBalloon,

      {

         time=500,

         xScale=1,

         yScale=1,

         y=finalY

      }))

   end

end

This is the listener: 

function onBalloonTouch( self, event )

      print (event.target.id) – this shows me that the event has triggered…it works for balloons from 1 to 35

      if event.phase == “began” then

         local idx = event.target.id

         if balloons[idx] ~= nil then

            removeBalloon(idx)

         end

      end

      return true

end

Any idea what is going on here ?

Thanks!

Emerson

Can you apply code tags to the code? It makes it really hard to read, which in turn makes it hard to help…

(you can edit your post and then use the  “< >” button after selecting your code)

DUDE!

I feel like an idiot (probably because I am one!).

I’ve copied the listener code from another place and totally forgot to remove the following stupid test:

      if objects[event.target.id] == nil then

          return true

      end

Sorry about that!

Emerson

Don’t worry about it. Even if you’ve been coding for years, anyone can just get really stuck and can’t see the trees from the forest. I probably solve one of my own posts at least twice a year. :wink:

Can you apply code tags to the code? It makes it really hard to read, which in turn makes it hard to help…

(you can edit your post and then use the  “< >” button after selecting your code)

DUDE!

I feel like an idiot (probably because I am one!).

I’ve copied the listener code from another place and totally forgot to remove the following stupid test:

      if objects[event.target.id] == nil then

          return true

      end

Sorry about that!

Emerson

Don’t worry about it. Even if you’ve been coding for years, anyone can just get really stuck and can’t see the trees from the forest. I probably solve one of my own posts at least twice a year. :wink: