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!
countdown timer script
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: countdown timer script
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:
...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
Re: countdown timer script
...and welcome to the LiveCode community and welcome back to xtalk.
-
- Posts: 5
- Joined: Wed May 04, 2011 12:19 am
Re: countdown timer script
Thanks, that's extremely helpful! I'm sure I'll be back with more questions after I try this out.
Thanks again!
Thanks again!
Re: countdown timer script
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.
I hope that this comment can be of help to someone.
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