|
Hemdall Wanderer
Joined: 30 Nov 2006 Posts: 50
|
Posted: Thu Feb 17, 2011 9:49 pm
Changing line blocks executing another triggers. |
Until today I was assuming all triggers with pattern matching the specific line executes at once but I was wrong. I've made two exactly the same triggers:
Code: |
<trigger priority="41970" case="true" regex="true" id="4197">
<pattern>^(?:> )?This is test\.$</pattern>
<value>#color blue
#sayadd { First trigger.}</value>
</trigger>
<trigger name="another trigger" priority="41970" case="true" regex="true" id="4198">
<pattern>^(?:> )?This is test\.$</pattern>
<value>#sayadd { Second trigger.}</value>
</trigger>
|
Because Trigger on Trigger is checked and Stop further processing is unchecked I expected both triggers to be executed but for my surprise only one has fired. Is that bug? |
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Fri Feb 18, 2011 3:40 am |
In the example above you have two problems. First both triggers have the same priority. Now if you change the priority of one of the triggers like I have below you will still only see one trigger fire. (The first one since that has the lowest priority.)
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<trigger name="another trigger" priority="41971" case="true" regex="true" copy="yes">
<pattern>^(?:> )?This is test\.$</pattern>
<value>#sayadd { Second trigger.}
</value>
</trigger>
<trigger priority="41970" case="true" regex="true" copy="yes">
<pattern>^(?:> )?This is test\.$</pattern>
<value>#color blue
#sayadd { First trigger.}
</value>
</trigger>
</cmud> |
At this point, once the first trigger fires and executes the #sayadd, the pattern for the second trigger no longer matches. So to make the second trigger fire you would need to have the pattern match This is test. First trigger. or throw in a wild card, or remove the anchor from the end of the pattern.
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<trigger priority="41970" case="true" regex="true" copy="yes">
<pattern>^(?:> )?This is test\.$</pattern>
<value>#color blue
#sayadd { First trigger.}
</value>
</trigger>
<trigger name="another trigger" priority="41971" case="true" regex="true" copy="yes">
<pattern>^(?:> )?This is test\..*$</pattern>
<value>#sayadd { Second trigger.}
</value>
</trigger>
</cmud> |
|
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
Hemdall Wanderer
Joined: 30 Nov 2006 Posts: 50
|
Posted: Fri Feb 18, 2011 10:39 am |
Yes, I know that. I was just assuming that once specific line arrives from mud all triggers with the same priority fires at once and are not dependant on other - this way once the trigger changes how line is displayed in output it is preventing another trigger with the same priority and matching pattern to work. Shouldn't with option Trigger on Trigger every matching trigger works on unchanged original line? At this moment line comes - one trigger fires, line is sent to output, second trigger works on sent (changed) line not original. For me it is slightly unpractical. Why? I always try to write as precise pattern as I can so there is no chance something with #sayadd will fire, or for example something with #sub. I write scripts for friends, but they don't use only mines but others too - now it is very difficult to share anything if they in some way changed how line is displayed in theirs script because simply like that my triggers won't fire. Sometimes it takes hours to explain how and what change to make everything work.
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Fri Feb 18, 2011 5:04 pm |
No, they do not. Only one trigger can fire at a time. That is a fundamental restriction of computers. You can't have two triggers trying to modify the same line at the same time. It is simply impossible. It would be impossible in any other computer language, as well--you can't have two threads changing the same variable at precisely the same time. First one goes, than the other. Triggers will fire in order by priority, and if they have identical priorities by some other order (probably ID). And no, having the Trigger on Trigger does not cause a trigger to work on the unchanged line--it simply means that it will work on the _output_ of another trigger.
[edit]If each trigger worked in a separate thread, you _could_ end up having both triggers firing on the unchanged line. But if that happened, one would finish first (possibly by a microsecond) and make its change to the unchanged text, then the other would finish and make it's change--to the _unchanged_ text again! They would not be able to actually change the text at the same exact moment. You would end up with only the change from the trigger that finished last. For this reason, among others, triggers all work in a single thread--the main thread, which also processes the command line--unless you specifically include a command that puts the trigger into a background thread. |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Sat Feb 19, 2011 8:05 pm |
One possibility depending on your usage scenario is to have you second trigger more general then use %line and %match or %regex to do what you want.
Alternatively you can combine the triggers and use %line to reference the original text. |
|
_________________ Asati di tempari! |
|
|
|
|
|