 |
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Thu Nov 22, 2007 8:08 pm
[2.x] Wait trigger states as alarms |
In recent times, when discussing alarms and #wait, I have suggested the use of a wait trigger state to accomplish the same. I was told that this system is flawed because it will only fire on the first line to be received after the wait period is up, and so relies on having many lines spammed in order for it to be accurate. This seemed odd to me, as I distinctly recall the zMud beta when multistate triggers were first implemented, and being told by Zugg that this is what the wait trigger state was designed for - to replace the buggy #wait in many scripts. However, I took the word of those who had told me this, as they are much more advanced users than I.
Then, I noticed some behaviour which suggested them to be wrong.
Create the following in the blank session window:
| Code: |
<trigger priority="10" id="1">
<pattern>Line1</pattern>
<trigger type="Wait" param="3000">
<value>#Sh 2nd has fired after 3s</value>
</trigger>
</trigger> |
Type in "#sh line1" at the command line. Observe the following output, with a 3 second delay between the two lines:
| Quote: |
line1
2nd has fired after 3s |
Being the untitled session, there were no incoming lines from the mud. It fired correctly after 3 seconds just as I had believed it did for years now.
I'm posting this because I have found this way of doing a simple alarm (obviously it is limited in use compared to alarms. Alarms have many more options such as repeating etc) but for a simple timer such as is commonly used for failsafes in curing you cannot beat the wait trigger state for controllability. You don't have to worry about thread creation, which window it is created in and will therefore fire in (if all alarms need to be created in a window and not a module, then their script will be executed if not globally, then in all packages enabled for that window.)
It occurred to me that the confusion is because most people don't actually know about the wait trig type function where you do not specify a pattern. The help file suggests a line is needed, as does simple logic when talking about a multistate trigger. However, there is the option of a trigger state that lacks a pattern completely.
To wrap it up, I am posting because I think the following example should be added to the help file:
| Quote: |
Wait
The specified number of milliseconds must have passed before the line of text is received from the MUD that matches the pattern field. (existing)
Additionally, if the pattern is left blank, the commands will be executed immediately after the specified number of milliseconds has passed. |
Additionally, the following should be considered for part of a tutorial on timers, which would also include examples of #ALARM and #WAIT, along with some pros and cons for each to help people make a decision on which to use.
| Quote: |
#TRIGGER "timer" {The first line of the timer}
#COND {} {#SH Timer has executed.} {wait|param=3000}
To begin the timer:
#STATE timer 1
To end it prematurely and not have the commands executed:
#STATE timer 0
To fire it early, executing the commands:
#SET timer 1 |
Note: I'm probably wrong about the cons I listed for #alarm. To be honest, a lot of the stuff in various threads concerning alarms confuses me, the most recent being the one on global alarms. Reading that thread is what made it occur to me that perhaps #alarm is often too powerful a tool for the job. |
|
_________________ Athlon 64 3200+
Win XP Pro x64 |
|
|
 |
Tech GURU

Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Fri Nov 23, 2007 1:39 am |
Caled, this isn't entirely. The reason you second state fires is that you are matching on a empty pattern ( with the default of option of trigger on new line ) so it will basically match on any line matched after three seconds. For the problem you are trying to address, it essentially works the same, but I just wanted to make that clarification.
|
|
_________________ Asati di tempari! |
|
|
 |
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Fri Nov 23, 2007 7:03 am |
I am saying that this is not the case. No line was received, it still fired. If I put * in the pattern, it would fire on any line. Having a blank pattern means it fires when the timer runs out, independent of lines received from the mud. My example above shows this to be true.
|
|
_________________ Athlon 64 3200+
Win XP Pro x64 |
|
|
 |
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Fri Nov 23, 2007 6:20 pm |
I don't have a recent version of CMUD installed on this computer, so, Caled, maybe instead of "#sh line1", you can do a "#sh line1;#THREAD" for us, so we can see if a new thread is spawned for the wait. From your post, it does sound like <trigger type="Wait" param="x"> with no pattern operates differently to one with patterns... (and this does ring a vague bell in my head).
|
|
|
|
 |
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Fri Nov 23, 2007 6:31 pm |
2.13 output for "#sh line1;#THREAD"
| Code: |
line1
Threads:
# ID Window Name Status Script
-------------------------------------------------------------------------------------------------
1 [u] untitled running #sh line1;#THREAD
2nd has fired after 3s
|
|
|
|
|
 |
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Fri Nov 23, 2007 6:44 pm |
Looks good then, I guess. Zugg probably forgot how these particular alarm triggers worked. This will be more efficient then creating one time alarms (although you can have alarms that you just enable and disable). #ALARMs currently do not create new threads - it was changed again, but I suppose it may yet change for a 3rd time if a good reason comes up. It could be that these particular alarm triggers work essentially the same as #ALARMs, using the same underlieing code.
|
|
|
|
 |
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Sat Nov 24, 2007 8:57 am |
I just like the controllability of it. Sure, alarms have #T+/-
But there is no #SET to finish it early AND execute the commands.
Plus, sometimes the first state of the trigger is not a dummy state, but an actual used/useful one, which makes your script neat.
Its also a pretty neat way to temporarily disable a trigger. I use it with my affliction tracker (that is, tracking my opponents' afflictions, not my own). I know they don't have salve balance for a second after I see them apply a salve.. so my trigger for them applying a salve has a blank wait state for 800ms.. which basically just disables the trig for that period after it fires. Its the more 'eloquent' solution than using an alarm or #wait.
Its just not really known about, though I think Larkin uses it occasionally in ACP. |
|
_________________ Athlon 64 3200+
Win XP Pro x64 |
|
|
 |
Tech GURU

Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Mon Nov 26, 2007 1:30 am |
| Caled wrote: |
| No line was received, it still fired. |
I tested this specifically earlier and I didn't get any response from this wait trigger until I sent another line. I'll do some more testing and post later tonight. |
|
_________________ Asati di tempari! |
|
|
 |
Tech GURU

Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Mon Nov 26, 2007 2:03 am |
I stand corrected, I'm not sure why it didn't work the first time I tested it but it does work as Arde describes.
|
|
_________________ Asati di tempari! |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Nov 26, 2007 5:10 pm |
| Quote: |
| Looks good then, I guess. Zugg probably forgot how these particular alarm triggers worked |
That's definitely possible! |
|
|
|
 |
|
|
|