Countdown Timer Suspends User Input (*NOOB*)

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
garrettgsb
Posts: 2
Joined: Tue Oct 21, 2014 2:16 am

Countdown Timer Suspends User Input (*NOOB*)

Post by garrettgsb » Tue Oct 21, 2014 2:47 am

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:

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Tue Oct 21, 2014 3:09 am

If you want messages to be sent during the wait add "with messages" to the end of the wait statement.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Tue Oct 21, 2014 3:31 am

Hi.

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

Craig Newman

garrettgsb
Posts: 2
Joined: Tue Oct 21, 2014 2:16 am

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

Post by garrettgsb » Tue Oct 21, 2014 3:36 am

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Tue Oct 21, 2014 4:28 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply