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
daemoan.vermillious
Apprentice


Joined: 28 Feb 2009
Posts: 135
Location: Chico, Ca

PostPosted: Sun Jan 24, 2010 7:30 am   

Generic Timer
 
If i just wanted to make a timer?
say like a 10 min count down timer?
and just resets and stops when it ends
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Jan 24, 2010 8:55 am   
 
Code:

#variable Timers {quest=1800|campaign=604800}
#alarm "tCountdown" {-1} {
  #forall "list|of|countdown|timers" {
    #if (%iskey(@Timers,%i) or (@Timers.%i > 0)) {
      #addkey Timers %i (@Timers.%i - 1)
    } {
      #delkey Timers %i
      #if (%numkeys(@Timers)) {#T- tCountdown}
    }
  }
}
_________________
EDIT: I didn't like my old signature
Reply with quote
daemoan.vermillious
Apprentice


Joined: 28 Feb 2009
Posts: 135
Location: Chico, Ca

PostPosted: Sun Jan 24, 2010 4:25 pm   
 
Thanks Matt, also was there a way to turn that on and off? start stop/reset...
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Jan 24, 2010 8:40 pm   
 
I didn't include one, but an example of one would be like this:

starting a new timer
Code:

#alias timer {
  #if (!%null(%1)) {
    #if (!%null(%2) and %isnumber(%2)) {
      #print %concat("<color red>ALIAS (timer):</color>",%1," <color white>timer with a duration of</color> ",%2," seconds <color white>has been added.</color>")
      #addkey Timers %1 %concat("active|",%2)
      //check status of tCountdown alarm
      #if (%trigger(tCountdown) {#T+ tCountdown}
    } {
      #print %concat("<color red>ALIAS (timer):</color><color white>timer duration not supplied or is not a number!</color>",%cr,"SYNTAX: timer name duration-in-seconds")
    }
  } {
    #print %concat("<color red>ALIAS (timer):</color><color white>showing list of timers currently counting down.</color>",%cr,%expanddb(@Countdowns,%cr,":"))
  }
}


The alarm's #forall list will need to be modified so that it can self-update (otherwise new timers you add won't count down). An easy fix for that is to rename the Timers variable to Countdowns, move all non-countdown timers to a different variable, and then just use @Countdowns in place of "list|of|countdown|timers".

To end a timer early, or to reset it to a different value, you can just reissue the timer.

to pause timers
Code:

#alias tpause {
  #switch (!%null(%1) and %iskey(@Countdowns,%1)) {
      #print %concat("<color red>ALIAS (tpause):</color>",%1," <color white>timer has been</color> ",%if(%item($timer,1) = "active","paused","activated"),"<color white>.</color>")
      $timer = @countdowns.%1
      #if (%item($timer,1) = "active") {$timer = %replaceitem("paused",1,$timer)} {$timer = %replaceitem("active",1,$timer)}
      #addkey Countdowns %1 $timer
    }
    (!%null(%1) and !%iskey(@Countdowns,%1)) {
      #print %concat("<color red>ALIAS (tpause):</color><color white>timer name not a valid timer!</color>",%cr,"SYNTAX: tpause name")
    }
    (%null(%1)) {
      #print %concat("<color red>ALIAS (tpause):</color><color white>timer name not supplied!</color>",%cr,"SYNTAX: tpause name")
    }
}


The alarm's #addkey command will be need to changed to:

$timer = @countdowns.%i
$timer = %replaceitem((%item($timer,2) - 1),2,$timer)
#addkey Countdowns %i $timer
_________________
EDIT: I didn't like my old signature
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Jan 25, 2010 1:27 pm   
 
I assume you also know about the Tick Timer, which can be used like this? See the help for "Tick Timer".
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