| 05-05-2008, 06:21 AM | #1 |
Is there a function that returns elapsed game time? Currently I'm using the following: JASS:globals timer GameTimer = null real gameLength = 0 endglobals function GetElapsedTime takes nothing returns real if GameTimer == null then return 0 else return gameLength + TimerGetElapsed (GameTimer) endif endfunction function GameTooLong takes nothing returns nothing set gameLength = gameLength + TimerGetTimeout (GameTimer) endfunction ... (initialization) set GameTimer = CreateTimer () call TimerStart (GameTimer, 3600, false, function GameTooLong) ... |
| 05-05-2008, 06:25 AM | #2 |
No there isn't, apart from creating a timer at the start of the game and then using TimerGetElapsed on that timer The problem is, as the game drags on the values returned by TimerGetElapsed gets more and more inaccurate, it seems to be a problem with how Wc3 does higher end real arithmetic. You can refer to this for more info http://www.wc3campaigns.net/showthread.php?t=10018 |
| 05-05-2008, 10:35 AM | #3 |
well that should be a problem because floats are accurate enough for the amount of time we can play .. |
| 05-05-2008, 10:55 AM | #4 |
Why not just get a variable and add 1 to it every second or something? |
| 05-05-2008, 10:57 AM | #5 |
strictly speaking, as the integer part of a float grows, it potentially loses precision in the non-integer part (obviously, since the storage has a fixed size). But GetElapsed could be inaccurate for many reasons (although it has been accurate when i used it but i guess it was for lower values) edit: yeah if you don't want high precision (just to seconds), it's easy to do it manually |
| 05-05-2008, 12:06 PM | #6 |
TimerGetElapsed does not get innacurate with time, unless you mention the usual float issue, the real problem is that using high values for the timer's timeout makes TimerGetElapsed horribly innacurate since the beginning. |
| 05-05-2008, 12:30 PM | #7 |
oh. interesting. i just checked, dota has a timer for determining game time, and starts it with 99999 seconds. shouldn't that be disastrous because of what you mentioned? or its good enough to get the current second? |
| 05-05-2008, 12:43 PM | #8 |
The innacuracy is an error of about 0.2, so many applications don't need it, and i think dota's is just to time stamp messages. JASS:library GameElapsedTime initializer init globals private real off=0.0 private timer T private constant real TIMEOUT=10.0 //too big: innacurate, too short, performance hit, I think 10.0 is fine to both reduce the error without affecting performance endglobals // guess what? It is inline-friendly function GameElapsedTime takes nothing returns real return off + TimerGetElapsed(T) endfunction private function onExpire takes nothing returns nothing set off=off+TIMEOUT endfunction private function init takes nothing returns nothing set T=CreateTimer() call TimerStart(T,TIMEOUT,true,function onExpire) endfunction endlibrary |
