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
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Wed Dec 31, 2008 6:32 pm   

What's the best mechanism to accomplish this?
 
My goal is to setup a trigger that operates as follows:

1) I push a macro and for 5 seconds after I push the macro it enables a regex.
2) If I push the macro again before the 5 seconds is up, the regex is renewed and says active for 5 seconds after the macro was pressed.

I've tried doing this with the regex trigger followed by the duration trigger, but this isn't quite what I'm looking for. The regex/duration doesn't renew the time if I hit the macro again. I'd have to wait for the 5 seconds to expire then press the macro again. During that brief time the regex would not be enabled.

The only way I can think of accomplishing this is to do the following:

macro #1 - Enables a regex and alarm when pressed
regex #2 - Is enabled when the macro is pressed
alarm #3 - Is enabled when the macro is pressed and disables the regex and alarm after 5 seconds. If the macro is pressed before the alarm executes it gets reset back to 5 second and thus doesn't disable the regex pre-maturely.

I've also tried to do this with a macro/set|duration type of combination, but it has the same results as doing a regex/duration in that re-pressing the macro doesn't extend it to 5 seconds.

Any ideas on how to make this a bit more eloquent?
Reply with quote
calesta
Apprentice


Joined: 07 Dec 2008
Posts: 102
Location: New Hampshire, USA

PostPosted: Wed Dec 31, 2008 7:46 pm   
 
In your macro you can check to see if the trigger is currently enabled or not using the %trigger function. If it isn't enabled, just enable it. If it is enabled, reset the trigger to the duration state using the #state command which should restart the duration timer.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger name="RegEx" type="Duration" param="5000" priority="20" regex="true" copy="yes">
    <pattern>^(\S+) tells you: (.*)$</pattern>
    <value>#show Fired</value>
    <trigger regex="true" enabled="false">
      <pattern>.*</pattern>
      <value>#show Disabling
#T- RegEx</value>
    </trigger>
  </trigger>
</cmud>

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <macro key="F1" copy="yes">
    <value>#show Enabling
#if (%trigger(RegEx)) {#state RegEx 0} {#T+ RegEx}</value>
  </macro>
</cmud>


The duration is only checked when a new line of text is received from the MUD though, so this still may not give you exactly what you want. For example, you press the macro which enables the trigger, no text is received for 6 seconds, and then the first text received matches the trigger. Conceptually since you have a 5 second duration on the trigger, it shouldn't fire... but since no lines were received in the interim, it still will fire in this case. If that is a problem, I can't think of any way other than what you have.

Edit: I make no claim that this is the best way to do this, it seems close to the way you were originally trying though Smile
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Wed Dec 31, 2008 8:03 pm   
 
I used a slight variation on what you had. I first tried using 'alarm' instead of regex so that it would fire after a period of time instead of when the next line came. It worked pretty well with a small time like *0.001 (*0 doesn't seem to work). But then I had the idea to use the pattern '.*' with reparse. As you can always match on the last line with that, it is always immediate.
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Wed Dec 31, 2008 8:49 pm   
 
I did it with
Code:
#t+ NameOfYourTrigger
#alarm NameOfYourAlarm +5 {#t- NameOfYourTrigger}

as my macro, it seemed to work OK (but you might want to specify a class for the alarm, since it's deleted and recreated frequently).

Edit: Don't forget to use something (probably an onConnect event) to make sure your trigger is disabled whenever you reconnect, in case you disconnect before the alarm goes or something anomalous.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Jan 01, 2009 5:29 am   
 
You could also try using the %alarm function to set the time remaining of the alarm back to 5 seconds, but I think I'd prefer gamma_ray's method, if it works.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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