OnTimer keeping correct time?
Is it slow?
Thursday, August 9, 2007 by sViz | Discussion: DesktopX
So if I counted by 10 every time, ontimer...
Sub Object_OnTimer1
milisec = milisec + 10
End Sub
...milisec should reach 1000 every second, on the second.
For a simple stopwatch I used the following code in a text object:
- Sub Object_OnTimer1
- If milisec > 999 Then
- milisec = 0
- sec = sec + 1
- If sec > 59 Then
- min = min + 1
- sec = 0
- End If
- If min > 59 Then
- hr = hr + 1
- min = 0
- End If
- If hr = 100 Then object.KillTimer 1
- Else
- milisec = milisec + 10
- End If
- txt = "0"
- If len(milisec) = 1 Then
- milisec = txt & txt & milisec
- Elseif len(milisec) = 2 then
- milisec = txt & milisec
- End if
- If len(sec) = 1 Then sec = txt & sec
- If len(min) = 1 Then min = txt & min
- If len(hr) = 1 Then hr = txt & hr
- Object.text = hr & ":" & min & ":" & sec & ":" & milisec
- End Sub
I let it run side by side with my system clock and my stopwatch is slower than the system time. It takes roughly TWO seconds for milisec to count to 1000. Am I missing something painfully obvious here?
Reply #2 Saturday, August 11, 2007 4:33 AM
- Dim milisec, sec, min, hr
- 'Called when the script is executed
- Sub Object_OnScriptEnter
- milisec = 0
- sec = 0
- min = 0
- hr = 0
- object.SetTimer 1,1000
- object.SetTimer 2,10
- End Sub
- Sub Object_Ontimer1
- milisec = 0
- sec = sec + 1
- If sec > 59 Then
- min = min + 1
- sec = 0
- End If
- If min > 59 Then
- hr = hr + 1
- min = 0
- End If
- If hr = 100 Then object.KillTimer 1
- End Sub
- Sub Object_OnTimer2
- If milisec > 999 Then
- milisec = 0
- Else
- milisec = milisec + 10
- End If
- txt = "0"
- If len(milisec) = 1 Then
- milisec = txt & txt & milisec
- ElseIf len(milisec) = 2 Then
- milisec = txt & milisec
- End If
- If len(sec) = 1 Then sec = txt & sec
- If len(min) = 1 Then min = txt & min
- If len(hr) = 1 Then hr = txt & hr
- Object.text = hr & ":" & min & ":" & sec & ":" & milisec
- End Sub
Please login to comment and/or vote for this skin.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
- Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
- Access to a great community, with a massive database of many, many areas of interest.
- Access to contests & subscription offers like exclusive emails.
- It's simple, and FREE!







Reply #1 Thursday, August 9, 2007 10:45 PM
I did something like this for practice some time ago and the only work-a-round I figure was two timers. In the first timer you'd put some type of IF STATEMENT to check against the rollover of the system clock.