Millisecs() and rollover

Blitz3D Forums/Blitz3D Programming/Millisecs() and rollover

Dip(Posted 2009) [#1]
I see Millisecs() on my machine returns the time since the last reboot. What happens if the machine has been on for a very long time? Given that each day has 86,400,000 milliseconds, and the maximum size of the integer data type is 2,147,483,647, Millisecs() will rollover in less than 25 days. What happens if I'm playing a game that uses Millisecs() on day 25? Will it flip over to -2,147,483,647, will it reset to 0, will it just crash? I can't wait 25 days to find out :)


John Blackledge(Posted 2009) [#2]
Exactly. Nobody leaves a game running for 25 days.


LineOf7s(Posted 2009) [#3]
http://www.blitzbasic.com/Community/posts.php?topic=84114#950040


Zethrax(Posted 2009) [#4]
Exactly. Nobody leaves a game running for 25 days.


That's a fairly dubious statement, John. Many programs may need to run for more than 25 days (gameservers, etc).

I could be wrong, but I think it's the operating system that needs to be running for 25+ days for this to happen, not the game - and many people do leave their computers on for that long.

@Dip - What happens is that the counter will flip over to the maximum negative integer (eg. -2,147,483,647) and will then begin counting up to the max positive value and then flip over again. The solution for this is to test for the difference between two timer values, rather than testing the time itself.

Here's some links with more info on the subject:-

http://www.blitzbasic.com/Community/posts.php?topic=78458#880544

http://www.blitzbasic.com/Community/posts.php?topic=49285#548324


GfK(Posted 2009) [#5]
Don't use Millisecs. Use a timer.


Dip(Posted 2009) [#6]


Wow, talk about right on time! Figures I didn't check the blitzmax forum when searching this issue, wasn't sure if the underlying code for that part was the same.

@John: Millisecs() goes from the start of the system, not the start of the game. You can verify this by running the code listed here: http://blitzbasic.com/Community/posts.php?topic=83218#939145

@GfK: I'm already using timers in a different part of the app. The use of Millisecs() is for synchronizing time between a client and server and using it to determine lag on the connection.

@Bill: Your second link leads to an internal error, but the first one tells me what I needed to know (along with Lineof7's). Thanks all for the help!