Advertisement
alestane

Scope correction

Apr 11th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bg = display.newRect (100,100, 300, 300)
  2.  
  3. local countdown
  4.  
  5. local function listener (event)
  6.     local r = math.random (1,255)
  7.     bg:setFillColor (r,r,r)
  8.     countdown = nil
  9. end
  10.  
  11. local function tl (event)
  12.     if event.phase == "ended" then
  13.         if countdown then
  14.             timer.cancel (countdown)
  15.             countdown = nil
  16.         end
  17.         countdown = timer.performWithDelay(500, listener)
  18.     end
  19. end
  20.  
  21. bg:addEventListener ("touch", tl)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement