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
itay1023
Posts: 68
Joined: Fri Sep 28, 2012 1:44 pm

timer

Post by itay1023 » Tue Sep 10, 2013 12:52 pm

hi,
i would like a code that count backwords one minute (60 seconds).

best regards'
Itay

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: timer

Post by BvG » Tue Sep 10, 2013 2:00 pm

Code: Select all

put the seconds into theCounter
put theCounter into theTime
repeat until theCounter - theTime >= 60
   put 60 - (theCounter - theTime) into field 1
   put the seconds into theCounter
   wait for 0.3 seconds with messages
end repeat
note: it's generally suggested to use send in time, and not repeat in these cases.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

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

Re: timer

Post by dunbarx » Tue Sep 10, 2013 8:08 pm

Itay:

Bernd's comment about sending in time is important, because it allows the computer to do other things while the counter is running. A repeat loop takes over everything unless you explicitly look out for other processes. In a button script on a card with a field:

Code: Select all

on mouseUp
   put the seconds into sTime
   put sTime + 60 into eTime
  countdown sTime,eTime
end mouseUp

on countDown sTime,eTime
   if the seconds > eTime then exit to top
   put 60 - (the seconds - sTime) into fld 1
   send "countDown sTime,eTime" to me in 1
end countDown
Note that this script runs much more often than once per second; it usually just reloads the same time value. It still leaves plenty of room for other things to happen, as you will see when you run it.

Craig

itay1023
Posts: 68
Joined: Fri Sep 28, 2012 1:44 pm

Re: timer

Post by itay1023 » Sun Sep 15, 2013 3:15 pm

It's good!!
Thank you very much!!

Post Reply