Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Grae
Beginner


Joined: 21 May 2006
Posts: 11

PostPosted: Thu Mar 26, 2009 6:32 am   

Problem with %secs?
 
I searched forums for a bit but could find no instance of this. Was working on moving a timer script across to cmud when I decided to re-write it, however I noticed a discrepancy between the output on Zmud and Cmud.


Current time: 2:25 am

output of #say %secs

Zmud:8764906

Cmud:35314397

Just to be rigorous, I did a %eval(%secs/3600000) --> translates to number of hours

Zmud:2
Cmud:9

Just to make sure I wasn't crazy, I checked the %time(), both gave me: Thursday March 26, 2009 2:25:15 am

Any explanation or am I just doing something completely stupid?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Mar 26, 2009 9:35 am   
 
zMud used the GetTickCount API call, which is less accurate and limited to 32bit. CMud uses QueryPerformanceCounter which is more accurate and is stored as a 64bit number. The number returned by %secs in CMud still has a unit of of milliseconds.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Grae
Beginner


Joined: 21 May 2006
Posts: 11

PostPosted: Thu Mar 26, 2009 9:36 am   
 
That's all well and good but why when I evaluate the millisecond time from midnight does the Cmud value show me 9 hrs when it was 2am i.e 2 hrs....
Reply with quote
Leitia
Adept


Joined: 04 May 2007
Posts: 292
Location: Boston

PostPosted: Thu Mar 26, 2009 10:23 am   
 
%eval(%secs/360000) returned 6 at 6:18 am, my seconds number was 2445844. The number you posted gave me zero, it was too big. I don't doubt there could be an issue, still
Reply with quote
Grae
Beginner


Joined: 21 May 2006
Posts: 11

PostPosted: Thu Mar 26, 2009 10:27 am   
 
Leitia wrote:
%eval(%secs/360000) returned 6 at 6:18 am, my seconds number was 2445844. The number you are using gave me zero, it was too big. I don't doubt there could be an issue, still
It is now 06:23am

%secs - 49559783
%eval(%secs/(60*60*1000) - 13
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Mar 26, 2009 10:33 am   
 
The %secs Predefined Variable doesn't do anything for midnight anymore. This was changed because many people wanted a high precision time counter and didn't want to have to adjust for going past midnight.

If you explain what you need to do with the script I am sure many of us would be willing to help point you to the best way to do it.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Grae
Beginner


Joined: 21 May 2006
Posts: 11

PostPosted: Thu Mar 26, 2009 11:25 am   
 
Finally an answer I can use....

The helpfile for Cmud still states that %secs begins counting at midnight, hence my confusion.

What is the time or origin for the new %secs?
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Mar 26, 2009 4:58 pm   
 
There isn't any defined "origin" for %secs anymore in CMUD. As Vijilante said, CMUD is now calling the QueryPerformanceCounter Windows API routine. The intent is to use %secs to perform relative timing tests and *not* to use %secs for any sort of absolute time. For absolute time, use the %time function, or the various Lua time functions.
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Thu Mar 26, 2009 5:27 pm   
 
I am now wondering if %secs would be suitable for measuring intervals of time such as 10 days? I've always wanted some time function in Cmud that is similar to the perl time() function which does the following:

Quote:

time

Returns the number of non-leap seconds since whatever time the system considers to be the epoch, suitable for feeding to gmtime and localtime. On most systems the epoch is 00:00:00 UTC, January 1, 1970; a prominent exception being Mac OS Classic which uses 00:00:00, January 1, 1904 in the current local time zone for its epoch.


Ten days would be 864,000,000 miliseconds, if it has 64 bits it would be limited to 1.844e19 if it is unsigned, so it might just be possible unless it is resetting it periodically.

Edit: I did some searching and found that it resets at reboot. That's a little disappointing, it is very useful for length of time based functions. I love being able to calculate large time intervals easily by simple subtraction of seconds rather than messing with # of days in a month, leap years, etc.

Hmm, it looks like Lua's time return is similar to Perl's and what I would need, I'll have to play around with using Lua for this.

Code:
Two functions, time and date, do all date and time queries in Lua.

The time function, when called without arguments, returns the current date and time, coded as a number. (In most systems, that number is the number of seconds since some epoch.)
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Thu Mar 26, 2009 6:13 pm   
 
Yeah, Lua will work just fine for this:
zs.var.var1 = math.floor(os.time() / (60*60*24))
Will return the number of days since the epoch. Now I can store that value and subtract subsequent ones to get the number of days between two times.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Mar 26, 2009 10:28 pm   
 
You could also store the os.time() result for a particular time (see the docs for os.date and os.time to see how they interact for doing that stuff) in case you want to use higher precision sometimes.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net