Time Counter
Malte Brill
revolution at derbrill.de
Tue Feb 22 07:24:41 EST 2005
Hi Signe,
>Thanks for the script, but there must be something missing. It does
not show
>the time elapsed. Only when I click the button does it change. What is
missing?
>Signe Marie
There shouldn´t be anything that´s missing (or doesn´t it count at
all?).
If you put the script into a button you need to click it once to start
the timer and a second time to stop it. If you want to start the timer
automaticly you can change the mouseUp handler to an openCard handler,
or whatever you need. I´ll comment the script below to make it more
understandable...
on mouseUp
--we need to call the startMyTimer handler fom somewhere
--this could also be on openCard or openStack
set the istimer of me to 0
--reset the timer
if the flag of me is empty then set the flag of me to -1
--initialize a flag custom property
--Using this cProp we can check if the timer is already running...
set the flag of me to the flag of me*-1
--change the flag if you click
--possible values are -1 and 1
--the first time you click it will set the cProp to 1
if the flag of me=1 then startMyTimer
--if the cProp is 1 then call the timer the first time
end mouseUp
on startMyTimer
set the isTimer of me to the isTimer of me+1
--increase the value of the timer. It will only count
put the isTimer of me div 60 into myMinutes
--calculate the number of whole minutes
if myMinutes<10 then put "0"&myMinutes into myMinutes
--if it is smaller than 10 then add an additional zero before it
put the isTimer of me mod 60 into mySeconds
--what´s left ofer when dividing by 60 is the seconds
if mySeconds<10 then put "0"&mySeconds into mySeconds
--add additional zero if necessary
put myminutes&":"&myseconds
--put minutes:seconds into msg
if the flag of me=1 then send startMyTimer to me in 1 second
--if the flag cProp of the calling object is 1 then call the
startMyTimer handler again
--so if you click the button holding the script again the flag will
be set to -1
--and the handler wont be called anymore
end startMyTimer
Hope this helps.
Malte
More information about the use-livecode
mailing list