 |
Scarn Apprentice
Joined: 24 Jul 2005 Posts: 137
|
Posted: Wed Feb 05, 2014 12:48 pm
Uptime Clock/Counter |
Hi,
On my MUD the uptime is displayed like this:
The Two Towers has been up for 4d 2h 15m 32s.
Is there any way I can record this data and have it displayed on my client without the need for massive of complicated timers and sums? |
|
|
|
 |
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Wed Feb 05, 2014 5:46 pm |
#trigger {^The Two Towers has been up for ([%d%ssmhd]).$} {Uptime = %1}
Then just make a button and put "Uptime: @Uptime" as the caption. This value will never update on its own, so you will also need an alarm to resend the command that displays that info to you. |
|
_________________ EDIT: I didn't like my old signature |
|
|
 |
Scarn Apprentice
Joined: 24 Jul 2005 Posts: 137
|
Posted: Thu Feb 06, 2014 8:24 am |
Yeah, that will spam up my client too much to play. :)
|
|
|
|
 |
shalimar GURU

Joined: 04 Aug 2002 Posts: 4799 Location: Pensacola, FL, USA
|
Posted: Thu Feb 06, 2014 7:20 pm |
not if you #GAG the output
|
|
|
|
 |
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Feb 06, 2014 11:20 pm |
Well, you said you didn't want complicated. What I gave you didn't do any calculating, it just relies on the appropriate command getting sent to the game.
To do complicated, you will want to first design and set up a separate script to manage the welcome phase of login (the point after name/password and before the prompt where your game starts sending you game text). The point of this script isn't actually to send each command you wish to execute right at login/reconnect, but to provide the gateway through which they will be run. This is the concept behind Object-Oriented Programming (OOP) and class objects (not to be confused with classes in CMud), so you can read up on that separately if you wish.
| Code: |
#trigger {^your mud's welcome message goes here$} {#raise onWelcome}
#trigger {^message you get for reconnecting to the game$} {#raise onWelcome}
|
As for the uptime script, the trigger I gave you originally can now be used as a calibrator to prevent your data from drifting too far off the mark due to processing lag (the type of lag you see if you were trying to use lots of memory-intensive tasks at the same time such as defragging your hard drive or running a security scan). The time-match calculation could be hidden away in a function, producing no output of any kind to spam the screen.
| Code: |
#function Uptime($start) {
//this example assumes a maximum time format of "Nd Nh Nm Ns"
//does not translate day amounts into weeks, months, or years
//assumes full format for lesser-interval zero values (ie, 2d 0h 4m 0s)
#local $interval $days $hours $minutes $seconds $result
//prepare start time and interval amount for calculation
#if (!%null(%2) and %isnumber(%2)) {$interval = %2} {$interval = 1}
#switch (%match($start,"(%d)d (%d)h (%d)m (%d)s",$days,$hours,$minutes,$seconds)) {
//all accounted for, no need to prep anything
}
(%match($start,"(%d)h (%d)m (%d)s",$hours,$minutes,$seconds)) {
$days = 0
}
(%match($start,"(%d)m (%d)s",$minutes,$seconds)) {
$days = 0
$hours = 0
}
(%match($start,"(%d)s",$seconds)) {
$days = 0
$hours = 0
$minutes = 0
}
//do calculations
#add $seconds $interval
#if ($seconds >= 60) {
$seconds = ($seconds - 60)
#add $minutes 1
}
#if ($minutes = 60) {
$minutes = 0
#add $hours 1
}
#if ($hours = 24) {
$hours = 0
#add $days 1
}
//prepare return value
#if ($days > 0) {$result = $days"d "}
#if ($hours > 0) {$result = $result" "$hours"h "}
#if ($minutes > 0) {$result = $result" "$minutes"m "}
$result = $result" "$seconds"s"
#return $result
}
|
$interval is the amount in seconds to update the value by each time the function is called. For example, if you wanted to only update once every minute it would be something like "Uptime = @Uptime(@Uptime,60)" (you would put this in an alarm that fires every 60 seconds). |
|
_________________ EDIT: I didn't like my old signature |
|
|
 |
|
|
|
|
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
|
|