counting time

Posted by Guest1 on Tue 04 Mar 2003 06:40 PM — 3 posts, 20,705 views.

USA #0
I think I saw a thread on this recently but just a bit of advice needed (or rather just to confirm I'm going about this the best way).

I have a counter that records total experience and coins gained during a group which I report avery so often to the group. Groups on average last for several hours. I have an alias that then resets it back to zero at the end of the group.

What I'm wanting to do is also add a time on that so that when I join a group and I reset my exp & coin counters to zero, it will also start a timer at the same time. When I report to the group the total exp & coin at any given time, it will also give the time taken so far, and calculate experience per hour based on that.

The calculation part is not a problem, I'm just trying to figure the best way to get the total time on it. It does not need to be extremely accurate, but I figured that I could have a timer that fires say every minute which grabs a variable (called total_time for example) and adds 1 to it. This variable would of course reset to zero whenever I reset the exp & coin totals.

The calculation part would then just grab that total_time variable and divide it by 60, then divide the total exp/coins by that result to give an average per hour.

All good, but is that timer firing every minute the best way to do it? I want as little disruption as possible to game play (lags etc when it fires) or would the timer firing have a negligible effect?

Thanks in advance for any advice (even if it's just to say I have the best way to do it).
USA #1
You could keep the time in a variable as well, something like:

a = DateDiff("n", world.getvariable("StartTime"), now)
world.send "party tell It has been " & a & " minutes since we started."

where:
yyyy = # years
q = # quarters
m = # months
y = day of year (Huh??)
d = # days
w = # weekdays
ww = weeks of year (Huh again???)
h = # hours
n = # minutes
s = # seconds

Though I suspect you would like to leave it at "n". ;)

You would basically just set the StartTime variable like 'world.setvariable "StartTime", now' at the same time that you reset everything else.

However, even calling a sub every x seconds is not a major issue. I have one that executes a call once every 10 seconds. It only becomes noticable on a 300mhz system and then only due to the fact that it calculates a color based on percentage of the spells expected duration and actual time passed and builds a line with about 40 colournote commands. However, that is the display part. The script that updates the actual times runs continuously at two second intervals even when the display itself goes idle (5 minutes after the last time I typed a command) and that script has no noticable effect on the client at all.
Amended on Tue 04 Mar 2003 09:41 PM by Shadowfyr
USA #2
hmmm that is true, a timer wouldn't even be needed with your suggestion.. however I've set it up the way I stated in my first post and it's working fine, the main advantage being I can switch the timer off and back on at any time if the group decides to have a 20 minute coffee break or something, which is pretty crucial for the results to be reasonably accurate (just disables the timer so it stops adding 1 to the total time variable every minute).

My main concern was disruption/lag with the timer calling a sub which calls a variable and then sets the variable to a new value every minute, but it doesn't appear to have much effect on gameplay that I can tell so far, so it's all good.

The only other problem I had was when trying to calculate the exp per hour immediately after resetting it ...because the value on reset was zero minutes, it crashed (froze) the client trying to divide 0 by 60 hehe. No worries, I now have it reset to 1 minute and 1 exp point instead of 0 on resets now. :)

thanks for advice Shadowfyr :)