lua - Adding a delay/timer -
this question has answer here:
- lua program delay 1 answer
i using corona sdk, lua main language. having problem code - when run it, automatically gives me values of 'light' in stated print out. set light = 2 , loop, supposed decrement light 1 each time, until <= 0. when run program, values show 1,0,-1 @ once. wondering if can add delay between each values.
i making "simon says" game, , because of this, boxes not light because runs @ once.
here code:
if(count%20 == count - math.floor(count/20)*20) clicked = 0 while(light >= 0) light = light - 1 print(light) end end
here simple timer.performwithdelay function of corona sdk. can view more here: https://docs.coronalabs.com/api/library/timer/performwithdelay.html
below sample code suits question.
note: based code presented code above.
local lights = 2 local timername -- add timer id timer can cancel later on local function myfunction() lights = lights - 1 if (lights >= 0) --do lights print(lights) else --terminate timer timer.cancel( timername ) end end if(count%20 == count - math.floor(count/20)*20) timername = timer.performwithdelay( 1000, myfunction, 0 ) end
Comments
Post a Comment