Coundown timer

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
magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Coundown timer

Post by magice » Thu Aug 18, 2011 12:54 am

I am writing an app that is basically several user settable countdown timers with alarms.
I have taken the approach of using nested if statements to evaluate the number of minutes hours and days and make adjustments every 60 seconds. this approach has my brain tied in knots. It only seems natural to do this instead with nested repeat loops, but doing so seems to require a wait command which ties up the system and is therefore not good.
I have been toying with the idea of working from the system clock, but this would be difficult since the timer needs to be able to count down days as well as hours and minutes, and calender variances make that a problem to code.

so my question is, does runrev have any kind of built in date difference and/or date addition function. for that matter does it have a built in timer function that I am missing?

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Coundown timer

Post by SparkOut » Thu Aug 18, 2011 1:17 am

Hi magice,

You need to look up "convert" and "date items" in the dictionary.

This will give you lots of information about how to handle date calculation, you can work with a date 6 weeks ahead by adding 42 to the "day" item, for instance and have the day and month items handle the new representation.

Timing is *not* best done with a wait loop. Use "send in <your specified time>" to add a message to the pending messages queue which will be handled at a given time.

For accuracy, personally I would do an "alarm" timing loop by finding the target time in seconds (or even milliseconds) and saving that. Then you can start out with a "send in <large time interval>" (so that unnecessary checks are not made until close to the target time) to a handler which then checks the difference between the current time in seconds and the target time in seconds (or milliseconds). As the difference decreases you could decrease the time interval before the next "send in <much smaller time interval>" until you are pinpoint accurate (at least as accurate as the computer clock on which the alarm is running anyway).

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Coundown timer

Post by magice » Mon Aug 22, 2011 1:23 pm

Thank you. This is not the direction I had planed on going, but it works and I can see lots of possibilities.

Post Reply