Page 1 of 1

Countdown Timer Suspends User Input (*NOOB*)

Posted: Tue Oct 21, 2014 2:47 am
by garrettgsb
Hi guys,

I've been playing with LiveCode for a week or two now, done the tutorials on the LiveCode website (culminating with the 3-5-7 game) and have since tried my hand at realizing a project that I've wanted to create for myself: A countdown timer, specifically to use at the gym. My end goal is to implement the following functions:
  • User can set any time desired (in seconds, I'm not really worried about minutes/hours)
    Can stop/start the timer at will (basic stopwatch functionality)
    Can be set to repeat the set time automatically (i.e. a round timer)
    Can set two (or more) intervals, e.g. 60 second interval followed by 20 second interval, and repeat. (Like 60 seconds of work, 20 seconds rest)
    Play a tone when an interval is completed
    And... Run on Android. Some day :)
That's the big picture. Right now, I'm just working on the countdown. I got it to work, in that I put a number into a field, click a button, and the number counts down by 1 every second until it reaches zero. Here's the code I used (on the button script):

Code: Select all

global timeLeft, interval
on mouseUp
   put field "timer" into interval
   put field "timer" into timeLeft
   startTimer
end mouseUp
command startTimer
   repeat for interval times
         wait 1 second
         get timeLeft - 1
         put it into timeLeft
         put timeLeft into field "timer"
      end repeat
end startTimer
My problem is, I can't do anything else while the timer is running... Any input (clicks, typing, etc.) isn't registered/executed until the timer is finished. This makes it problematic to program a stop/reset button, as button clicks don't register until after the timer has reached 0. How do I allow the user to continue to do stuff even while the timer is running?

Please keep the explanations kindergarten-level; I'm a total newb to LiveCode and don't have any previous coding experience. This is my first non-tutorial attempt at creating an app :shock:

Re: Countdown Timer Suspends User Input (*NOOB*)

Posted: Tue Oct 21, 2014 3:09 am
by FourthWorld
If you want messages to be sent during the wait add "with messages" to the end of the wait statement.

Re: Countdown Timer Suspends User Input (*NOOB*)

Posted: Tue Oct 21, 2014 3:31 am
by dunbarx
Hi.

You are on your way. Keep at it, Write back.

Craig Newman

Re: Countdown Timer Suspends User Input (*NOOB*)

Posted: Tue Oct 21, 2014 3:36 am
by garrettgsb
FourthWorld wrote:If you want messages to be sent during the wait add "with messages" to the end of the wait statement.
Wow, jackpot! Yes, that was exactly what I needed, and now nothing can stop me!*

*Until I have another question

Thanks for the rapid and on-point response, I'll keep updating this thread as I get further in.

Re: Countdown Timer Suspends User Input (*NOOB*)

Posted: Tue Oct 21, 2014 4:28 pm
by FourthWorld
garrettgsb wrote: now nothing can stop me!*
That's the spirit! With that sort of feeling guiding your work, it will be truly the case.