Reset Script for Clock 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
timbrian
Posts: 6
Joined: Sat Jan 17, 2015 12:51 am

Reset Script for Clock Timer

Post by timbrian » Mon Mar 02, 2015 12:59 am

I've borrowed bits and pieces from other post for my clock script.
The script is to time the length of a baseball game based on first pitch and last out.
I can get the clock to start and stop, but my reset script merely clears out the game clock field
but does not reset the timer as hoped. Any help with reset code would be much appreciated.

Clock Script
local tsec, tmin, thr

on mouseUp
If the label of ME is "First Pitch" then
set the label of ME to "Final Out"
set the backgroundcolor of ME to gray
set the foregroundcolor of me to red

else
set the label ME to "First Pitch"
set the backgroundcolor of ME to green
set the foregroundcolor of Me to black

end if

startClock field GameClock
end mouseUp
on startClock

set the numberFormat to "00"
add 1 to tSec
if tSec = 60 then
add 1 to tMin
put 00 into tSec
If tMin = 60 then
add 1 to tHr
put 00 into tmin
end if
end if
if tMin = 0 then put 00 into tMin
if tHr = 0 then put 00 into tHr

put tHr & ":"& tMin & ":" & tSec into fld GameClock

if label of button "ClockButton" is "First Pitch"
else

send startClock to me in 1 sec --go back to the top and do it again in 1 sec

end if
end startClock
on TimesUp


end TimesUp

Reset Script
local tsec, tmin, thr

on mouseUp
If the label of me is "RESET" then
put 00 into tSec
put 00 into tMin
put 00 into tHr
put empty into field "GameClock"
end if


end mouseUp
Tim
Louisville, Ky

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

Re: Reset Script for Clock Timer

Post by magice » Mon Mar 02, 2015 1:18 am

Here's a hint. Look up pendingMessages in the dictionary. Also, if the reset script is in another button, make the variables global and declare them in both button scripts.

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

Re: Reset Script for Clock Timer

Post by dunbarx » Mon Mar 02, 2015 3:28 am

Hi.

You cannot have two handlers of the same name in the same script. Actually, you can, but only the first one will be executed.

But now I think your reset script is in a separate button, no? It was not clear in your post. Anyway, so when you put empty into the field, you have not stopped the clock routine, which is happily incrementing the field based on variables internal to its handler.

This is all good stuff, even though it does not work quite as well as you wish. What you have created is logical, but it does not quite yet fit into a framework that LC will process in the way you want.

Here is another hint.

Keep this all in one handler. Test for some condition, for right now, perhaps the mouseClick or the pressing of the optionKey. Do all your clean-up stuff, and then "exit to top". This will pull you out of the running handler, based on a condition within that handler.

Write back if this seems unclear. We will work this back and forth for a while, unless someone just (HARRUMPH) steps in and supplies a handler. When we are done, you will have a single handler of perhaps 20 lines total. It is not unusual for new programers to be overly wordy. This is how you learn. When we whittle this down, do take the time to see how the trimming is done, and without loss of readability.

Craig Newman

Post Reply