Timer algorithm
Posted: Sun Dec 31, 2023 12:24 pm
I have a problem on mobile that I am not good enough to solve and I hope some one can give me some hints...
My standalone shows two timers, the Match timer and the Set timer.
The Match timer start at 00:00:00 at the beginning of a match and should always run till the end of it.
The Set timer start at 00:00:00 at the beginning of a match BUT gets zeroed at the end of each set and start a new counting for the next Set.
This is because at the end of a match, I need to have a Match time that is the sum of each Set time (there could be up to 5 Sets in a match).
Running a recursive command every seconds, and adding 1 sec to each counter, doesn't work because other scripts delay in a noticeable way the counters (in respect to the OS clock).
So, I am using the following (simplified version):
It works fine, keeping the timers accurate.
My problem is the "undo":
Because players may score a wrong point, they are able to revert to the previous score, but both timers meanwhile should keep running.
No problem when there is an undo during a Set, but if the undo happens just when a new Set has been started, like for example Match timer= 00:02:25 and Set Timer= 00:00:00 (because at the start of each Set the SetTimer gets reset), I don't know how to reset the sSetTimeDiff value so that everything works as it should.
Time is tough and this is a conceptual problem that my age prevents me from solving...
Thanks for any help.
Trevix
My standalone shows two timers, the Match timer and the Set timer.
The Match timer start at 00:00:00 at the beginning of a match and should always run till the end of it.
The Set timer start at 00:00:00 at the beginning of a match BUT gets zeroed at the end of each set and start a new counting for the next Set.
This is because at the end of a match, I need to have a Match time that is the sum of each Set time (there could be up to 5 Sets in a match).
Running a recursive command every seconds, and adding 1 sec to each counter, doesn't work because other scripts delay in a noticeable way the counters (in respect to the OS clock).
So, I am using the following (simplified version):
Code: Select all
local sMatchTimeDiff, sSetTimeDiff
On MatchStart
put the seconds into tNow
put tNow into tNowItems
convert tNowItems to dateitems
put item 1 to 3 of tNowItems,0,0,0,item 7 of tNowItems into tTime
convert tTime to seconds
put tNow - tTime into sMatchTimeDiff --difference in seconds between clock time and match time
put sMatchTimeDiff into sSetTimeDiff --same difference at match start
RunMatchTimer
end MatchStart
On RunMatchTimer
put the seconds into tNow
put tNow - sMatchTimeDiff into tMatchTime
convert tMatchTime to long time
--do the set
put tNow - sSetTimeDiff into tSetTime
convert tSetTime to long time
put tMatchTime into fld "MatchTime"
put tSetTime into fld "SetTime"
send "RunMatchTimer" to me in 1 seconds
end RunMatchTimer
My problem is the "undo":
Because players may score a wrong point, they are able to revert to the previous score, but both timers meanwhile should keep running.
No problem when there is an undo during a Set, but if the undo happens just when a new Set has been started, like for example Match timer= 00:02:25 and Set Timer= 00:00:00 (because at the start of each Set the SetTimer gets reset), I don't know how to reset the sSetTimeDiff value so that everything works as it should.
Time is tough and this is a conceptual problem that my age prevents me from solving...
Thanks for any help.
Trevix