title: How to make my sensor to work properly in corona sdk?
body: <p>This is the code:</p>
  
  <pre><code>local bottombar = display.newLine(0, 480, 340, 480)
  physics.addBody(bottombar, "static", {isSensor = true})
  
  function bottombar:collision(event)
      if(event.phase == "began") then
          a = a + 1
          print(a)
  
          if(a == 4) then
              timer.cancel(timer1) 
              storyboard.gotoScene("scene_results")
          end
      end
  end
  
  bottombar:addEventListener("collision", bottombar)
  
  end
  </code></pre>
  
  <p>The game generate balls who fall and and i want to stop the game when 3 balls pass thru the bottom line.Variable 'a' initially is 0,when the first ball pass thru the line in console 'a' is 1,when the second ball pass thru the line the console shows me that 'a' is 2 and on the next line 3 like this:</p>
  
  <pre><code>1   =&gt; first ball
  2  }
     }=&gt; second ball
  3  }  
  </code></pre>
  
  <p>If i make <code>if(a == 10)</code> for 1st ball 'a' is 1,for 2nd ball 'a' is (2, 3),for the 3th 'a' is (4, 5, 6) and when the 4th ball passes thru the line 'a' is (7, 8, 9, 10).</p>
  
  <p>Or if i destroy 3 balls(<code>self:removeSelf()</code> when i touch them) and i let the 4th ball to pass thru line the 'a' become: </p>
  
  <pre><code>1
  2
  3
  4
  </code></pre>
  
  <p>I'm sorry if i have grammatical mistakes.</p>
  
  <p>This is the whole code, I can't figure out what i'm doing wrong:</p>
  
  <pre><code>local a = 0
  local score = 0
  
  local function game()
      local pop = audio.loadSound("pop.WAV")
      local masterVolume = audio.getVolume()
  
      local function createCircle()
          function onCircleTouch(self, event)
              if(event.phase == "began") then
                  timer.performWithDelay(1, function() 
                      self:removeSelf() 
                      audio.play(pop,{channel=0,loops=0}) 
                      score=score+10  
                      globals.score = score 
                  end )
              end
              return true
          end
          local circle = display.newImage("ballon2.png",math.random(10,300),0)
          physics.addBody( circle, "dynamic", { desity=1.0,friction=0 })
          circle.touch = onCircleTouch
          circle:addEventListener("touch", circle)
      end      
  
      local function balls(event) 
          createCircle()
          local bottombar=display.newLine(0, 480, 340, 480)
          physics.addBody(bottombar, "static" ,{isSensor=true})
          function bottombar:collision(event)
              if(event.phase == "began") then
                  a=a+1
                  print (a, event.other)
                  if( a == 3) then
                      timer.cancel(timer1)
                      storyboard.gotoScene( "scene_results" )
                  end
              end
          end
          bottombar:addEventListener("collision", bottombar)
      end
  
      timer1=timer.performWithDelay( 1000, balls, 0 )
  end
  
  game()
  </code></pre>