Best GetCurrentRealTime() Timer?

Post » Mon May 05, 2014 4:49 pm

What's the best way to use GetCurrentRealTime() as a timer?

I was thinking that something like this would work...
Float fTime = Utility.GetCurrentRealTime()While fTime < (fTime + 5.0)	fTime = Utility.GetCurrentRealTime()EndWhile
...but the loop doesn't seem to end.
User avatar
Jodie Bardgett
 
Posts: 3491
Joined: Sat Jul 29, 2006 9:38 pm

Post » Mon May 05, 2014 3:41 pm

The loop never ends because every time you increase fTime, the (fTime + 5) increases by the same amount. Thus it's basically always checked for X to stop being < X + 5 which is impossible.

Before doing the while loop, create another variable and set it to the current time + 5, then check for that variable instead. See below for example:

Float fTime = Utility.GetCurrentRealTime()Float fTarget = (Utility.GetCurrentRealTime() + 5)While fTime < (fTarget)	fTime = Utility.GetCurrentRealTime()EndWhile
Also, since this will run every single tick, if you don't need it to be precise you should add a 'Utility.Wait(1.0)' after the line that updates fTime inside of the while. However, if this is literally a timer for 5 seconds don't do it. But if you were timing something like 3 minutes, you wouldn't need precision, and could save some on performance.
User avatar
neen
 
Posts: 3517
Joined: Sun Nov 26, 2006 1:19 pm


Return to V - Skyrim