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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
danextpope
Newbie


Joined: 11 Apr 2007
Posts: 9

PostPosted: Tue Apr 17, 2007 11:27 pm   

[DragonRealms] Best way to repeat a command with a delay?
 
Often I wish to send a command a fixed number of times with a fixed delay between commands. I've come of with two ways of doing this, and am curious about the pros and cons of each method. For the samples, I'm assuming the command is "juggle" and the delay is 12 seconds.


  • Recursively. We create an alias that calls itself, decreasing the count argument:
    Code:

    #alias dosomething {
      juggle
      #if (%1 > 1) {
        #alarm +12 {dosomething %eval(%1 - 1)}
      }
    }

  • Procedurally, creating a whole bunch of alarms:
    Code:

    #alias dosomething {
      juggle
      #loop %eval(%1 - 1) {
        #alarm +%eval(12 * %i)
      }



Both will create n-1 alarms, but the first only has one going at a time, while the second has them all at once. On the other hand, the first alias will be called n times, while the second one gets called once. So, any thoughts? Or suggestions of a better way of doing this?
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Tue Apr 17, 2007 11:40 pm   
 
Performance-wise I don't think there's much of a difference. I'd generally plump for having only one going at a time though so that if I needed to abandon the alarms halfway through it'd be easy to introduce a break variable and have #if (@break = 1) to determine whether to create the alarm etc.
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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