countdown timer script

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
awesomeandrew
Posts: 5
Joined: Wed May 04, 2011 12:19 am

countdown timer script

Post by awesomeandrew » Wed May 04, 2011 12:28 am

Hi!

I am learning all about LiveCode after many years off the scripting horse. I took some Hypercard programming classes about 20 years ago and loved it, and I'm really excited to have found LiveCode!

I want to make a task-timing application and am not sure where to begin. I've looked at several tutorials, read some of the user guide, searched the forums, and I'm still not sure what to do.

My question for you is: How can I make a field in which I enter a number (the goal time) and then press a start button, which then counts the number down to zero allowing for pauses to switch to other tasks? I've written a script for a button that starts the countdown, but I can't seem to pause it in an orderly fashion which keeps track of the new, smaller number!

In case it's relevant, I'm not concerned about the date and time in this situation, I just want to keep track of whether or not I'm completing tasks in the desired number of minutes and seconds.

thanks for any advice you can give!

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: countdown timer script

Post by mwieder » Wed May 04, 2011 1:25 am

Without seeing your script, my guess is that you're doing something like "wait 1 second", then continuing with the loop. You can probably get by with "wait 1 second with messages" to allow the system time to do housekeeping, but...

...try using "send in time" instead, as in:

Code: Select all

local sCountDownValue
on mouseUp
  put 30 into sCountDownValue
  put sCountDownValue into field "fldCount"
  send "updateMe" to me in 1 second
end mouseUp

on updateMe
  subtract 1 from sCountDownValue
  put sCountDownValue into field "fldCount"
  if sCountDownValue > 0 then
    send "updateMe" to me in 1 second
  end if
end updateMe

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: countdown timer script

Post by mwieder » Wed May 04, 2011 1:26 am

...and welcome to the LiveCode community and welcome back to xtalk.

awesomeandrew
Posts: 5
Joined: Wed May 04, 2011 12:19 am

Re: countdown timer script

Post by awesomeandrew » Wed May 04, 2011 1:38 am

Thanks, that's extremely helpful! I'm sure I'll be back with more questions after I try this out.

Thanks again!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: countdown timer script

Post by Mag » Sun Feb 23, 2014 2:23 pm

I'm working on a timer in these days, so I would like to add a comment.

Basing time calculation on commands such as "add", "subtract" and so on is fast but not very accurate because the timer will tend to be back over time (and it could also temporary stop whether the computer goes in sleep mode). If accuracy is important to you, I think it is always best to refer to the clock of the computer for time calculation. You decide a point in time, for example in ticks and then do the calculation.

Code: Select all

current time - final time = how much time is remaining
I hope that this comment can be of help to someone.

Post Reply