Forums » Bugs

LUA: gkmisc.GetGameTime() int overflow

Mar 28, 2010 meridian link
My Timer plug-in ( http://www.vendetta-online.com/x/msgboard/9/22074 ) saves the value of gkmisc.GetGameTime() to the wgaf.cfg file using gkini.WriteInt(). I have discovered an issue that cropped up recently that apparently is due to the fact that gkmisc.GetGameTime() (2822672745 as of right now) now exceeds the maximum value that can be saved.

I can fix my plug-in by dividing the value of gkmisc.GetGameTime() by 1000 before saving the value to the config file. I'll lose millisecond precision on a reload or logoff, but that's no big deal.

I just wanted to bring this issue to the attention of the devs and other plug-in writers in case it may be causing other plug-in or game-breaking features elsewhere.
Mar 29, 2010 raybondo link
The Game Time is reset when the server is restarted and would wrap if the server were up for more than about 49.7 days (well, actually probably about half that since we reset the time to some large value on startup), so keeping that value is meaningless during those times.

Printing GetGameTime() through lua would probably not print it correctly and truncate some bits of precision, like you're noticing. Well, also that WriteInt is signed and the gametime is unsigned.

Dividing by 1000 is probably your best bet.

It's not something we're going to 'fix'.

A better option is for you to use os.time() (if it is available in the sandbox, I forget). That is second accurate, will not wrap until around 2038, and is consistent across server restarts.
Mar 29, 2010 meridian link
I did not realize that GetGameTime() was reset on a server restart. I was mistakenly thinking that this was the first time in 5 years or so that the value of GetGameTime() exceeded the maximum value savable to WriteInt().

Thanks for the explanation Ray, it was very helpful.
Mar 29, 2010 PaKettle link
If you want to keep the precision you can whack off a few digits from the front and store them separately.