Countdown HH:MM:SS

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Countdown HH:MM:SS

Roger Eller
I know I can convert the time to seconds, do the math, split it up into
HH:MM:SS, and repeat a "send myCounter in 1 sec" to update a countdown timer
field, but before I begin chiseling on a new square wheel, is there a better
(shorter) way?

˜Roger
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

dunbarxx
Hi.


Shorter? It already can be pretty short. MUCH shorter? Where's  Colin?


Craig Newman





-----Original Message-----
From: Roger Eller <[hidden email]>
To: How to use LiveCode <[hidden email]>
Sent: Tue, Jul 19, 2011 5:36 pm
Subject: Countdown HH:MM:SS


I know I can convert the time to seconds, do the math, split it up into
HH:MM:SS, and repeat a "send myCounter in 1 sec" to update a countdown timer
field, but before I begin chiseling on a new square wheel, is there a better
(shorter) way?

˜Roger
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

Jeffrey Massung
Lookup the "convert" function... dateAndTime and look at the format
"dateItems". That probably has what you care about.

HTH,

Jeff M.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

Ken Ray
In reply to this post by dunbarxx

On Jul 19, 2011, at 10:00 PM, [hidden email] wrote:

> Hi.
>
>
> Shorter? It already can be pretty short. MUCH shorter? Where's  Colin?

Here's the fastest way I know:

on mouseUp
  DisplayTime
end mouseUp

on DisplayTime
  put the long time into tTime
  convert tTime to dateItems
  split tTime by ","
  put format("%02d:%02d:%02d",tTime[4],tTime[5],tTime[6]) into fld "Time"
  send "DisplayTime" to me in 1 second
end DisplayTime



Ken Ray
Sons of Thunder Software, Inc.
Email: [hidden email]
Web Site: http://www.sonsothunder.com/       

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

Roger Eller
On Wed, Jul 20, 2011 at 2:12 AM, Ken Ray wrote:

>
> On Jul 19, 2011, at 10:00 PM, [hidden email] wrote:
>
> > Hi.
> >
> >
> > Shorter? It already can be pretty short. MUCH shorter? Where's  Colin?
>
> Here's the fastest way I know:
>
> on mouseUp
>  DisplayTime
> end mouseUp
>
> on DisplayTime
>  put the long time into tTime
>  convert tTime to dateItems
>  split tTime by ","
>  put format("%02d:%02d:%02d",tTime[4],tTime[5],tTime[6]) into fld "Time"
>  send "DisplayTime" to me in 1 second
> end DisplayTime
>
>
> Ken Ray
> Sons of Thunder Software, Inc.
> Email: [hidden email]
> Web Site: http://www.sonsothunder.com/
>
>
Using the dateItems is definitely the right direction, but my objective is
to count backwards from for example; 2 hours, 45 minutes, and 59 seconds
while updating the display field every second.  When the countdown reaches
00:00:00, I would play a sound of do other actions.

˜Roger
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

jim hurley
In reply to this post by Roger Eller
Roger
 
Is this what you are looking for?

on mouseUp
   set itemdel to ":"
   put the long time into tTime
   put char 1 to -4 of tTime into field 1
   convert tTime to dateItems
   set the hms of me to tTime
   countDown
end mouseUp

on countDown
   put the hms of me into temp
   subtract 1 from item -2 of temp
   --The dateItems will take care of the negative seconds
   convert temp to dateItems
   set the hms of me to temp
   put temp into tDisplayTIme
   put item -4 to -2 of   tDisplayTIme into temp2
   replace "," with ":" in temp2
   put temp2 into field 1
   send countDown to me in 1 sec
   --Change the "1 sec" to "1 Minute" when you are sure it works for you.
end countDown

Jim Hurley


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

jim hurley
In reply to this post by Roger Eller
Roger,

I forgot the stop clause. Maybe:

if field 1 is "0:0:0"  then --or whatever
  --Do your business
else
   send countDown to me in 1 sec
end if

> Roger
>
> Is this what you are looking for?
>
> on mouseUp
>   set itemdel to ":"
>   put the long time into tTime
>   put char 1 to -4 of tTime into field 1
>   convert tTime to dateItems
>   set the hms of me to tTime
>   countDown
> end mouseUp
>
> on countDown
>   put the hms of me into temp
>   subtract 1 from item -2 of temp
>   --The dateItems will take care of the negative seconds
>   convert temp to dateItems
>   set the hms of me to temp
>   put temp into tDisplayTIme
>   put item -4 to -2 of   tDisplayTIme into temp2
>   replace "," with ":" in temp2
>   put temp2 into field 1
>   send countDown to me in 1 sec
>   --Change the "1 sec" to "1 Minute" when you are sure it works for you.
> end countDown
>
> Jim Hurley
>

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

slylabs13
In reply to this post by jim hurley
Hey as long as we are talking about dates and times, I am going to need soon a method to determine if a block of time intersects with another. Specifically I will need to do this in an SQL query. I suppose the best way would be to store all dates in julian format, then have a query that, given savedStartDate and savedEndDate are columns in a table, goes something like :

select * where (startDate > savedStartDate and startDate < savedEndDate) or (endDate > savedStartDate and endDate < savedEndDate)

Is that about right? Any other ideas?

Bob


On Jul 20, 2011, at 8:29 AM, James Hurley wrote:

> Roger
>
> Is this what you are looking for?
>
> on mouseUp
>   set itemdel to ":"
>   put the long time into tTime
>   put char 1 to -4 of tTime into field 1
>   convert tTime to dateItems
>   set the hms of me to tTime
>   countDown
> end mouseUp
>
> on countDown
>   put the hms of me into temp
>   subtract 1 from item -2 of temp
>   --The dateItems will take care of the negative seconds
>   convert temp to dateItems
>   set the hms of me to temp
>   put temp into tDisplayTIme
>   put item -4 to -2 of   tDisplayTIme into temp2
>   replace "," with ":" in temp2
>   put temp2 into field 1
>   send countDown to me in 1 sec
>   --Change the "1 sec" to "1 Minute" when you are sure it works for you.
> end countDown
>
> Jim Hurley
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

Ken Ray
In reply to this post by Roger Eller
> Using the dateItems is definitely the right direction, but my objective is
> to count backwards from for example; 2 hours, 45 minutes, and 59 seconds
> while updating the display field every second.  When the countdown reaches
> 00:00:00, I would play a sound of do other actions.

Sorry about that... this will work if you just want to count down from a fixed amount of time:

on mouseUp
  DoCountDown "2:45:59"
end mouseUp

on DoCountDown pTime
  convert pTime to seconds
  subtract 1 from pTime
  convert pTime to dateItems
  split pTime by ","
  put format("%02d:%02d:%02d",pTime[4],pTime[5],pTime[6]) into tNewTime
  put tNewTime into fld "Time"
  if tNewTime = "00:00:00" then
    TimesUp
  else
    send "DoCountDown tNewTime" to me in 1 second
  end if
end DoCountDown

on TimesUp
  answer "Done"
end TimesUp

Ken Ray
Sons of Thunder Software, Inc.
Email: [hidden email]
Web Site: http://www.sonsothunder.com/       

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

Peter Haworth-2
In reply to this post by slylabs13
Hi Bob,
Depending on your requirements, your tests might ned to be >= and <=.  Also,
SQL has a BETWEEN operator that would make your code a little more
readable:

"SELECT * FROM xyz WHERE startDate BETWEEN savedStartDate AND
savedEndDate...".

I don't think you need to store your dates in julian format.  The standard
SQL storage format of YYYY-MM-DD should work for your comparisons as long as
startdate is in that format also (I think).  If not, SQL (at least sqlite)
has date conversion expressions you can use to convert the dates to Julian
before the comparison:

SELECT * FROM xyz WHERE strftime(%J,startDate) BETWEEN
strftime(%J,savedStartDate) AND strftime(%J,savedEndDate)..."

mySQL does not have a Julian day conversion expression, but it does have a
TO_DAYS function so, as long as your dates are not before 1582 (!!!):

"SELECT * FROM xyz WHERE TO_DAYS(startDate) BETWEEN TO_DAYS(savedStartDate)
AND TO_DAYS(SavedEndDate)..."

For a system that is supposed to adhere to a standard, SQL has a remarkable
number of variations in its various implementations!


Pete
Molly's Revenge <http://www.mollysrevenge.com>




On Wed, Jul 20, 2011 at 9:32 AM, Bob Sneidar <[hidden email]> wrote:

> Hey as long as we are talking about dates and times, I am going to need
> soon a method to determine if a block of time intersects with another.
> Specifically I will need to do this in an SQL query. I suppose the best way
> would be to store all dates in julian format, then have a query that, given
> savedStartDate and savedEndDate are columns in a table, goes something like
> :
>
> select * where (startDate > savedStartDate and startDate < savedEndDate) or
> (endDate > savedStartDate and endDate < savedEndDate)
>
> Is that about right? Any other ideas?
>
> Bob
>
>
> On Jul 20, 2011, at 8:29 AM, James Hurley wrote:
>
> > Roger
> >
> > Is this what you are looking for?
> >
> > on mouseUp
> >   set itemdel to ":"
> >   put the long time into tTime
> >   put char 1 to -4 of tTime into field 1
> >   convert tTime to dateItems
> >   set the hms of me to tTime
> >   countDown
> > end mouseUp
> >
> > on countDown
> >   put the hms of me into temp
> >   subtract 1 from item -2 of temp
> >   --The dateItems will take care of the negative seconds
> >   convert temp to dateItems
> >   set the hms of me to temp
> >   put temp into tDisplayTIme
> >   put item -4 to -2 of   tDisplayTIme into temp2
> >   replace "," with ":" in temp2
> >   put temp2 into field 1
> >   send countDown to me in 1 sec
> >   --Change the "1 sec" to "1 Minute" when you are sure it works for you.
> > end countDown
> >
> > Jim Hurley
> >
> >
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

slylabs13
Ah! Very useful thank you!

Bob


On Jul 20, 2011, at 10:50 AM, Pete wrote:

> Hi Bob,
> Depending on your requirements, your tests might ned to be >= and <=.  Also,
> SQL has a BETWEEN operator that would make your code a little more
> readable:
>
> "SELECT * FROM xyz WHERE startDate BETWEEN savedStartDate AND
> savedEndDate...".
>
> I don't think you need to store your dates in julian format.  The standard
> SQL storage format of YYYY-MM-DD should work for your comparisons as long as
> startdate is in that format also (I think).  If not, SQL (at least sqlite)
> has date conversion expressions you can use to convert the dates to Julian
> before the comparison:
>
> SELECT * FROM xyz WHERE strftime(%J,startDate) BETWEEN
> strftime(%J,savedStartDate) AND strftime(%J,savedEndDate)..."
>
> mySQL does not have a Julian day conversion expression, but it does have a
> TO_DAYS function so, as long as your dates are not before 1582 (!!!):
>
> "SELECT * FROM xyz WHERE TO_DAYS(startDate) BETWEEN TO_DAYS(savedStartDate)
> AND TO_DAYS(SavedEndDate)..."
>
> For a system that is supposed to adhere to a standard, SQL has a remarkable
> number of variations in its various implementations!
>
>
> Pete
> Molly's Revenge <http://www.mollysrevenge.com>
>
>
>
>
> On Wed, Jul 20, 2011 at 9:32 AM, Bob Sneidar <[hidden email]> wrote:
>
>> Hey as long as we are talking about dates and times, I am going to need
>> soon a method to determine if a block of time intersects with another.
>> Specifically I will need to do this in an SQL query. I suppose the best way
>> would be to store all dates in julian format, then have a query that, given
>> savedStartDate and savedEndDate are columns in a table, goes something like
>> :
>>
>> select * where (startDate > savedStartDate and startDate < savedEndDate) or
>> (endDate > savedStartDate and endDate < savedEndDate)
>>
>> Is that about right? Any other ideas?
>>
>> Bob
>>
>>
>> On Jul 20, 2011, at 8:29 AM, James Hurley wrote:
>>
>>> Roger
>>>
>>> Is this what you are looking for?
>>>
>>> on mouseUp
>>>  set itemdel to ":"
>>>  put the long time into tTime
>>>  put char 1 to -4 of tTime into field 1
>>>  convert tTime to dateItems
>>>  set the hms of me to tTime
>>>  countDown
>>> end mouseUp
>>>
>>> on countDown
>>>  put the hms of me into temp
>>>  subtract 1 from item -2 of temp
>>>  --The dateItems will take care of the negative seconds
>>>  convert temp to dateItems
>>>  set the hms of me to temp
>>>  put temp into tDisplayTIme
>>>  put item -4 to -2 of   tDisplayTIme into temp2
>>>  replace "," with ":" in temp2
>>>  put temp2 into field 1
>>>  send countDown to me in 1 sec
>>>  --Change the "1 sec" to "1 Minute" when you are sure it works for you.
>>> end countDown
>>>
>>> Jim Hurley
>>>
>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

Roger Eller
In reply to this post by Ken Ray
On Wed, Jul 20, 2011 at 1:06 PM, Ken Ray wrote:

> > Using the dateItems is definitely the right direction, but my objective
> is
> > to count backwards from for example; 2 hours, 45 minutes, and 59 seconds
> > while updating the display field every second.  When the countdown
> reaches
> > 00:00:00, I would play a sound of do other actions.
>
> Sorry about that... this will work if you just want to count down from a
> fixed amount of time:
>
> on mouseUp
>  DoCountDown "2:45:59"
> end mouseUp
>
> on DoCountDown pTime
>  convert pTime to seconds
>  subtract 1 from pTime
>   convert pTime to dateItems
>  split pTime by ","
>   put format("%02d:%02d:%02d",pTime[4],pTime[5],pTime[6]) into tNewTime
>  put tNewTime into fld "Time"
>  if tNewTime = "00:00:00" then
>    TimesUp
>  else
>    send "DoCountDown tNewTime" to me in 1 second
>  end if
> end DoCountDown
>
> on TimesUp
>  answer "Done"
> end TimesUp
>
> Ken Ray
> Sons of Thunder Software, Inc.
> Email: [hidden email]
> Web Site: http://www.sonsothunder.com/
>
>
With only a few tweaks like handling a cancel/reset request, this script
does what I need. James' was almost the one, but the time wasn't starting
from a pre-set amount of time such as 1 hour, etc.  Thanks to everyone that
contributed!

~Roger
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

Nonsanity-2
I wouldn't rely on the send in time structure to actually fire every second.
It's going to slip over time as the computer takes periodic spikes of use.
If you want New Years Eve accuracy of the final countdown, you should
probably re-calculate the delta based on the current time continuously.

Here's the code from a quick test stack's single button. There are also
three fields.

on mouseup
   put the internet date into fld 1 -- display the current time
   get fld 2 -- get the target time
   convert it to seconds
   set the targetTime of me to it
   UpdateCountdown
end mouseup

on UpdateCountdown
   get the targetTime of me
   put CountdownCalc( it ) into fld 3 -- display the countdown
   -- always best to make sure this timer loop hasn't already been started
   if "UpdateDountdown" is not in the pendingmessages then send
"UpdateCountdown" to me in 1 second
end UpdateCountdown

function CountdownCalc targetTime -- in seconds
   put targetTime - the seconds into deltaTime
   put trunc(deltaTime / 3600) into h -- hours
   put trunc((deltaTime - (h * 3600)) / 60) into m -- minutes
   put deltaTime - (h * 3600) - (m * 60) into s -- seconds
   put format( "%i:%02i:%02i", h, m, s ) into countdown
   return countdown
end CountdownCalc


Pretty much the same as the other samples, but more accurate over the long
haul in those final seconds.


 ~ Chris Innanen
 ~ Nonsanity



On Wed, Jul 20, 2011 at 3:19 PM, Roger Eller <[hidden email]>wrote:

> On Wed, Jul 20, 2011 at 1:06 PM, Ken Ray wrote:
>
> > > Using the dateItems is definitely the right direction, but my objective
> > is
> > > to count backwards from for example; 2 hours, 45 minutes, and 59
> seconds
> > > while updating the display field every second.  When the countdown
> > reaches
> > > 00:00:00, I would play a sound of do other actions.
> >
> > Sorry about that... this will work if you just want to count down from a
> > fixed amount of time:
> >
> > on mouseUp
> >  DoCountDown "2:45:59"
> > end mouseUp
> >
> > on DoCountDown pTime
> >  convert pTime to seconds
> >  subtract 1 from pTime
> >   convert pTime to dateItems
> >  split pTime by ","
> >   put format("%02d:%02d:%02d",pTime[4],pTime[5],pTime[6]) into tNewTime
> >  put tNewTime into fld "Time"
> >  if tNewTime = "00:00:00" then
> >    TimesUp
> >  else
> >    send "DoCountDown tNewTime" to me in 1 second
> >  end if
> > end DoCountDown
> >
> > on TimesUp
> >  answer "Done"
> > end TimesUp
> >
> > Ken Ray
> > Sons of Thunder Software, Inc.
> > Email: [hidden email]
> > Web Site: http://www.sonsothunder.com/
> >
> >
> With only a few tweaks like handling a cancel/reset request, this script
> does what I need. James' was almost the one, but the time wasn't starting
> from a pre-set amount of time such as 1 hour, etc.  Thanks to everyone that
> contributed!
>
> ~Roger
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

Nonsanity-2
Or with the other features you mentioned:


on mouseup -- start 1 hour timer button
   get the seconds
   put it into now
   convert now to internet date
   put now into fld 1 -- display the current time

   add 3600 to it -- one hour from now
   set the targetTime of me to it
   convert it to internet date
   put it into fld 2 -- display the target time
   UpdateCountdown
end mouseup

on UpdateCountdown
   get the targetTime of me
   if it is empty then exit UpdateCountdown
   put CountdownCalc( it ) into res
   if char 1 of res is "-" or res = "0:00:00" then
      -- timer ended
      set the targetTime of me to empty
      put "0:00:00" into res
   end if
   put res into fld 3 -- display the countdown
   -- always best to make sure this timer loop hasn't already been started
   if "UpdateDountdown" is not in the pendingmessages then send
"UpdateCountdown" to me in 1 second
end UpdateCountdown

function CountdownCalc targetTime -- in seconds
   put targetTime - the seconds into deltaTime
   put trunc(deltaTime / 3600) into h -- hours
   put trunc((deltaTime - (h * 3600)) / 60) into m -- minutes
   put deltaTime - (h * 3600) - (m * 60) into s -- seconds
   put format( "%01i:%02i:%02i", h, m, s ) into countdown
   return countdown
end CountdownCalc


on MouseUp -- cancel button
   set the targetTime of me to empty
end MouseUp


 ~ Chris Innanen
 ~ Nonsanity


> On Wed, Jul 20, 2011 at 3:19 PM, Roger Eller <[hidden email]>wrote:
>
>>
>> With only a few tweaks like handling a cancel/reset request, this script
>> does what I need. James' was almost the one, but the time wasn't starting
>> from a pre-set amount of time such as 1 hour, etc.  Thanks to everyone
>> that
>> contributed!
>>
>> ~Roger
>>
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

ScottR
In reply to this post by Nonsanity-2
Recently, Nonsanity wrote:

> I wouldn't rely on the send in time structure to actually fire every second.
> It's going to slip over time as the computer takes periodic spikes of use.
> If you want New Years Eve accuracy of the final countdown, you should
> probably re-calculate the delta based on the current time continuously.

Agreed.  A few years back, Geoff Canyon came up with the following which has
been reliable for me:

 send "someMsg" to someObj in (1 - (the long seconds mod 1)) seconds

Regards,

Scott Rossi
Creative Director
Tactile Media, UX Design



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

Roger Eller
On Wed, Jul 20, 2011 at 6:20 PM, Scott Rossi wrote:

> Recently, Nonsanity wrote:
>
> > I wouldn't rely on the send in time structure to actually fire every
> second.
> > It's going to slip over time as the computer takes periodic spikes of
> use.
> > If you want New Years Eve accuracy of the final countdown, you should
> > probably re-calculate the delta based on the current time continuously.
>
> Agreed.  A few years back, Geoff Canyon came up with the following which
> has
> been reliable for me:
>
>  send "someMsg" to someObj in (1 - (the long seconds mod 1)) seconds
>
> Regards,
>
> Scott Rossi
> Creative Director
> Tactile Media, UX Design
>

The variety of flavors in script methods to achieve a countdown timer are
obviously many.  The first place I looked for such was in revOnline (user
samples).  Would those of you in this thread that contributed a version of a
solution (Ken, Chris, James, others) be ok with me compiling these into a
stack and posting it there?  Of course credits would be given to each
scriptor for their contribution.  I'm thinking this would be useful to both
new and seasoned devs.  Thanks guys!

˜Roger
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

Ken Ray
>
> The variety of flavors in script methods to achieve a countdown timer are
> obviously many.  The first place I looked for such was in revOnline (user
> samples).  Would those of you in this thread that contributed a version of a
> solution (Ken, Chris, James, others) be ok with me compiling these into a
> stack and posting it there?  Of course credits would be given to each
> scriptor for their contribution.  I'm thinking this would be useful to both
> new and seasoned devs.  Thanks guys!

Fine by me!

Ken Ray
Sons of Thunder Software, Inc.
Email: [hidden email]
Web Site: http://www.sonsothunder.com/       

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Countdown HH:MM:SS

jim hurley
In reply to this post by Roger Eller
>
> Message: 15
> Date: Wed, 20 Jul 2011 15:19:07 -0400
> From: Roger Eller <[hidden email]>
> To: How to use LiveCode <[hidden email]>
> Subject: Re: Countdown HH:MM:SS
> Message-ID:
> <CAAT6EXPFGQY-=S6irWxERo3BXK=[hidden email]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Wed, Jul 20, 2011 at 1:06 PM, Ken Ray wrote:
>
>>> Using the dateItems is definitely the right direction, but my objective
>> is
>>> to count backwards from for example; 2 hours, 45 minutes, and 59 seconds
>>> while updating the display field every second.  When the countdown
>> reaches
>>> 00:00:00, I would play a sound of do other actions.
>>
>> Sorry about that... this will work if you just want to count down from a
>> fixed amount of time:
>>
>> on mouseUp
>> DoCountDown "2:45:59"
>> end mouseUp
>>
>> on DoCountDown pTime
>> convert pTime to seconds
>> subtract 1 from pTime
>>  convert pTime to dateItems
>> split pTime by ","
>>  put format("%02d:%02d:%02d",pTime[4],pTime[5],pTime[6]) into tNewTime
>> put tNewTime into fld "Time"
>> if tNewTime = "00:00:00" then
>>   TimesUp
>> else
>>   send "DoCountDown tNewTime" to me in 1 second
>> end if
>> end DoCountDown
>>
>> on TimesUp
>> answer "Done"
>> end TimesUp
>>
>> Ken Ray
>> Sons of Thunder Software, Inc.
>> Email: [hidden email]
>> Web Site: http://www.sonsothunder.com/
>>
>>
> With only a few tweaks like handling a cancel/reset request, this script
> does what I need. James' was almost the one, but the time wasn't starting
> from a pre-set amount of time such as 1 hour, etc.  Thanks to everyone that
> contributed!
>
> ~Roger
>


Roger,

Good decision. Ken's solution is MUCH cleaner.

Jim Hurley



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode