Ok, it's sorted. Thanks to all who have contributed to my latest angst.
The answer is that "send xxx to me in yyyy seconds" is never going to be accurate. So all those answers about implementing timers I've read are wrong.
I started to think laterally and wondered if Livecode has access to Unix Time - the number of seconds or milliseconds since 00.00.00 on 1st January 1970. I've used it before in other contexts. As it turns out Livecode does have access called, somewhat unhelpfully, "the milliseconds". And whilst searching on this I came across a posting which explains exactly why sending stuff is never going to be accurate in itself. Thanks to hliljegren on Stackoverfow
http://stackoverflow.com/questions/2933 ... n-livecode
Basically your send command will be in a varying sized queue so you need to refer to something accurate - Unix Time - or at least your computer time, which is based on seriously accurate clocks. Then although you "send xxx to me in yyyy seconds" you refer to an accurate time in each loop, and the result comes out working correctly.
This is my new version, based on the answer in Stackoverflow
Code: Select all
-- @@@@@@@@@@@@@@@@@@@@@@@@@
local lStartTime, lTimerTime
on showTime
put the milliseconds into lStartTime --put current Unix time into a variable
put lStartTime + totalsecs * 1000 into lTimerTime -- add to it the start duration of the clip in milliseconds
runTimer -- run the handler below
end showTime
on runTimer
put lTimerTime - the milliseconds into tTimeLeft
-- So, subtract the current Unix time which is bigger now, from the result in showTime above which is lTimerTime.
-- The difference is smaller - so we're counting down
-- to keep consistency with the rest of the system I put the current duration in seconds back into totalsecs
put tTimeLeft/1000 into totalsecs
then
-- do the time maths
set numberformat to "xx"
put totalsecs div 3600 into xhrs
put (totalsecs mod 3600) div 60 into xmins
put trunc((totalsecs mod 3600) mod 60) into xsecs
--put the numbers on the screen
put xhrs into field "xHr" of card "pop1" of stack "pop"
put xmins into field "xMin" of card "pop1" of stack "pop"
put xsecs into field "xSec" of card "pop1" of stack "pop"
--then
send "runTimer" to me in 100 milliseconds
-- this loops in a nominal 100mSecs but it doesn't matter if it's inaccurate
else -- we're done with this
-- change the button setup
set the disabled of button "player1" of card "clipper" of stack "main" to "false"
--reset everything
set the cMediaOnFlag of stack "main" to 0 --reset the clip running flag
set the visible of field "board1" of card "clipper" of stack "main" to "false" -- don't show the "clip playing" sign
put 00 into field "xSec" of card "pop1" of stack "pop" -- put 00s on the screen
put 00 into field "xMin" of card "pop1" of stack "pop"
put 00 into field "xHr" of card "pop1" of stack "pop"
put 0 into xsecs -- reset the variables
put 0 into xmins
put 0 into xhrs
end if
end runTimer
Ok, on to the next problem.....
bernie