Thread: Timevar?
View Single Post
  #2  
Old 05-10-2011, 03:27 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Well, timevar increases by 1 every 5 seconds. timevar2 is the number of seconds since the UNIX epoch (midnight 1st January 1970).

If you save timevar2's value somewhere (for example, clientr.lasttime), you can then do something like timevar2 - clientr.lasttime to see how many seconds have passed since the flag clientr.lasttime was set. You could even do something like if ((timevar2 - clientr.lasttime) > 30) which would check if the flag was set over 30 seconds ago.

The only problem is that timevar2's behaviour is not perfect on the clientside, it works differently on Windows/Mac/Linux (on Windows, it returns how many seconds the client has been open, whereas on Mac and Linux it returns the seconds since the UNIX epoch based on the system clock/timezone). On the serverside though it will work well, and should provide good relative calculations. Plain ol' timevar, on the other hand, should be the same on both clientside and serverside (it is synchronised by the client automatically), but the fact that it increases by 1 every 5 seconds makes it a much less accurate measure of time.
__________________
Skyld
Reply With Quote