| View previous topic :: View next topic |
| Author |
Message |
abedour
Joined: 29 Oct 2010 Posts: 33
|
Posted: Tue Oct 04, 2011 2:41 am Post subject: Timers |
|
|
Curious if anyone knows how to update a timer (to the second) to display in days/hours/minutes. What I'm attempting to do is show a timer on the left side of my prompt showing how long I've been connected. So far, I can (obviously) only do seconds, but I have no idea how to format it to show dd:hh:nn
Any ideas? |
|
| Back to top |
|
 |
abedour
Joined: 29 Oct 2010 Posts: 33
|
Posted: Tue Oct 04, 2011 3:18 am Post subject: |
|
|
So far I have this (and it works great, not sure about performance wise)
| Code: | #tick {curtime}
{
#format timestamp3 {%t} {%X};
#format {sep} {%h} {};
#replace {sep} {#} {<faf>-};
#format timestamp0 {%.5s} {$timestamp3};
#var curtime {<G02><aaa>@clock{$hour}:@clock{$minute}:@clock{$seconds}<088> };
#showme {$curtime} {0}
}
{0.001}
#event {SESSION CONNECTED}
{
#var minute 0;
#var hour 0;
#var seconds 0
}
#function {clock}
{
#if {@count{%1} == 1} {
#format {clock} {%s%s} {0} {%1};
#return $clock
};
#else {#return %1}
}
#tick {ctime}
{
#math seconds {$seconds +1};
#if {$seconds >= 60} {#math {minute} {$minute + 1}; #var seconds 0};
#if {$minute >= 60} {#math {hour} {$hour + 1};#var minute 0;#var seconds 0}
}
{1}
|
|
|
| Back to top |
|
 |
Scandum Site Admin
Joined: 03 Dec 2004 Posts: 3274
|
Posted: Tue Oct 04, 2011 7:24 am Post subject: |
|
|
Check man strftime for available options.
The following is a lil more condensed.
| Code: |
#tick {curtime}
{
#format curtime %t {<G02><aaa>%H:%M:%S<088> };
#showme {$curtime} {0}
}
{1}
#event {RECEIVED INPUT}
{
#format curtime %t {<G02><aaa>%H:%M:%S<088> };
#showme {$curtime} {0}
}
|
|
|
| Back to top |
|
 |
abedour
Joined: 29 Oct 2010 Posts: 33
|
Posted: Tue Oct 04, 2011 11:22 am Post subject: |
|
|
Awesome, I understand how -that- works, but I'm talking about a timer that starts from 0 seconds, and ends at whatever (let's say I play for 3 hours straight) and the timer is updated at the left side of my prompt every second.
What you gave me is current time. What about a custom timer from point a to point be? I know #format <blah> %U and %T might have something to do with it, but I dunno how to, like, asctime the two of them after they're subtracted from one another. |
|
| Back to top |
|
 |
Slysven
Joined: 10 Apr 2011 Posts: 254 Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK
|
Posted: Tue Oct 04, 2011 9:00 pm Post subject: |
|
|
Try using a #FORMAT starttime {%T} at the start of the session to capture the unix epoch time (seconds since midnight 1 Jan 1970) and another one in the ticker and received line event to capture the time at that point - use #MATH to subtract the start time and then stick the resulting value as a variable into (I think) the end of the format string in the shown #format lines. The time versions of the format command only use the current time if they are NOT supplied with a time to use...
Note for anybody experimenting off-line, i.e. trying to work out the exact details when not connected to a MUD - the gts (initial) sesson does NOT seem to execute any #TICKER events - you can program them but they don't run. Is that intentional, Mr Scandum?
| Code: | #TICKER {curtime}
{
#FORMAT now %T;
#MATH elapsed $now-$starttime;
#FORMAT displaytime %t {{<G02><aaa>%H:%M:%S<088> }{$elapsed}};
#SHOWME {$displaytime} {0}
}
{1}
#EVENT {SESSION CONNECTED}
{
#FORMAT starttime {%T}
}
#EVENT {RECEIVED INPUT}
{
#FORMAT now %T;
#MATH elapsed $now-$starttime;
#FORMAT displaytime %t {{<G02><aaa>%H:%M:%S<088> }{$elapsed}};
#SHOWME {$displaytime} {0}
}
Edit: Oops - should have been CONNECTED not START in EVENT |
Of course you could use an #EVENT {SECOND} (note NO seconds value after the word SECOND here so it matches every different value of second in a minute and runs every second) as an alternative to a #TICKER; this WILL work in the gts session.
Last edited by Slysven on Wed Oct 05, 2011 4:27 pm; edited 2 times in total |
|
| Back to top |
|
 |
Scandum Site Admin
Joined: 03 Dec 2004 Posts: 3274
|
Posted: Tue Oct 04, 2011 10:19 pm Post subject: |
|
|
Triggers set in the startup session are inherited by a MUD session, and it's annoying when tickers intended for the MUD session run in the startup session.
One solution is to add a 4th argument to the session command where people can provide a script file that is read on a successful connect, there's probably a better way to go about it though. |
|
| Back to top |
|
 |
abedour
Joined: 29 Oct 2010 Posts: 33
|
Posted: Wed Oct 05, 2011 11:43 am Post subject: |
|
|
Very cool Slysven, however, when I used the #format display %T {{%H:%M:%S} {$elapsed}} it shows the correct format of, let's say 120 seconds into 2 minutes, however, it always adds 19 to it.
For instance
19:02:00 is the product of #format display %T {{%H:%M:%S} {120}}
and
20:40:00 is the product of #format display %T {{%H:%M:%S} {6000}}
Any idea why? Still not a secure way to gather asctime, or it's a bug? |
|
| Back to top |
|
 |
Slysven
Joined: 10 Apr 2011 Posts: 254 Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK
|
Posted: Wed Oct 05, 2011 4:22 pm Post subject: |
|
|
Note that the upper case %T in the #FORMAT gets the epoch time; the lower case %t displays the given time or epoch time if no time value is supplied and I have used both in the code I presented....
Mr Scandum - is the fourth #SESSION argument for an alias to run on session start up just an idea or has it actually been implimented? I note that there is the #EVENT {SESSION CONNECTED} option but I always wondered how you could program that before the session was started so that it could be called as the session started?  |
|
| Back to top |
|
 |
Scandum Site Admin
Joined: 03 Dec 2004 Posts: 3274
|
Posted: Wed Oct 05, 2011 4:29 pm Post subject: |
|
|
It gives a date somewhere in 1970 if you use 0.
#math accepts time values, so to calculate the offset use:
#math offset 24:00:00 - 19:00:00 which gives 18000, so:
#format display %t {{%H:%M:%S} {18000}}
which will give you 00:00:00 and will count up to 23:59:59 in 24 hours if you keep adding to it. |
|
| Back to top |
|
 |
Slysven
Joined: 10 Apr 2011 Posts: 254 Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK
|
Posted: Wed Oct 05, 2011 7:14 pm Post subject: |
|
|
Sorry, think we got wires crossed there - just saying that I thought abedour had used a 'T' when he shoulda used 't'  |
|
| Back to top |
|
 |
abedour
Joined: 29 Oct 2010 Posts: 33
|
Posted: Wed Oct 05, 2011 9:42 pm Post subject: |
|
|
I used %t, not %T, sorry. I created a work around regardless:
| Code: |
#format now {%T};
#math elapsed1 $now-$starttime;
#math elapsed {-68400 + $elapsed1};
#format displaytime %t {{%H:%M:%S} {$elapsed}};
|
Works like a charm. |
|
| Back to top |
|
 |
Slysven
Joined: 10 Apr 2011 Posts: 254 Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK
|
Posted: Thu Oct 06, 2011 8:36 am Post subject: |
|
|
Just to save you a step, I think you can have more than 2 arguments to a #MATH calculation, try:
| Code: | | #MATH elapsed {$now-$starttime-68400}; |
|
|
| Back to top |
|
 |
Slysven
Joined: 10 Apr 2011 Posts: 254 Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK
|
Posted: Fri Oct 07, 2011 9:35 am Post subject: |
|
|
| Just a thought about the odd whole number of hours offset you seemed to be getting. We ARE talking about time aren't we and underlying the TinTIn commands is the 'C' date/time functions so your locale settings may be playing a factor in the time calculations. I'm in the UK so currently I'm one hour ahead of UTC whereas I guess you (abedour) are in the USA and are (I guess) 5 hours behind? Maybe that offset is changing your results... |
|
| Back to top |
|
 |
Scandum Site Admin
Joined: 03 Dec 2004 Posts: 3274
|
Posted: Fri Oct 07, 2011 9:29 pm Post subject: |
|
|
You can always settle for:
| Code: |
#format now {%T};
#math elapsed $now - $starttime;
#format displaytime {%02m:%02m:%02m} {$elapsed / 3600} {$elapsed % 3600 / 60} {$elapsed % 60}
|
|
|
| Back to top |
|
 |
|