Implementing a countdown timer
To implement a countdown timer, we will create two objects: a field to display the current timer and a button to start the countdown. We will code two handlers: one for the button and one for the timer.
How to do it...
Perform the following steps to create a countdown timer:
- Create a new main stack.
- Place a field on the stack's card and name it
timerDisplay
. - Place a button on the stack's card and name it
Count Down
. - Add the following code to the
Count Down
button:on mouseUp local pTime put 19 into pTime put pTime into fld "timerDisplay" countDownTimer pTime end mouseUp
- Add the following code to the
Count Down
button:on countDownTimer currentTimerValue subtract 1 from currentTimerValue put currentTimerValue into fld "timerDisplay" if currentTimerValue > 0 then send "countDownTimer" && currentTimerValue to me in 1 sec end if end countDownTimer
- Test the code using a mobile simulator or...