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
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Mon Aug 29, 2011 1:14 am   

[BUG: 3.34Pro] Optional newlines in regex patterns makes triggers fire twice
 
When you have an optional newline in a regex pattern (\n?) the trigger fires twice, once without the newline portion and once with it. Simple test trigger:
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger priority="27050" regex="true" copy="yes">
    <pattern>^(abc)$(?:\n^(123)$)?</pattern>
    <value>#win testing "Trigger fired - %1: "%1"   %2: "%2</value>
  </trigger>
</cmud>

#show abc;#show 123 on the command line produces the following in the window:
Code:
Trigger fired - %1: abc   %2:
Trigger fired - %1: abc   %2: 123

As you can see, the same trigger is firing twice on the same output, which shouldn't be happening. If you remove the \n from the optional part of the trigger, it only fires once.

A slightly more complex, four line example:
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger priority="27050" regex="true" copy="yes">
    <pattern>^(abc)$(?:\n^(123)$(?:\n^(def)$(?:\n^(456)$)?)?)?</pattern>
    <value>#win testing "Trigger fired - %1: "%1"   %2: "%2"   %3: "%3"   %4: "%4</value>
  </trigger>
</cmud>

Then #show abc;#show 123;#show def;#show 456 displays
Code:
Trigger fired - %1: abc   %2:    %3:    %4:
Trigger fired - %1: abc   %2: 123   %3:    %4:
Trigger fired - %1: abc   %2: 123   %3: def   %4:
Trigger fired - %1: abc   %2: 123   %3: def   %4: 456

Now the single trigger is firing four times on the same output.
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Mon Aug 29, 2011 2:41 am   
 
That seems like it's working as it should. CMUD checks for trigger matches every line, so when it gets the first line, it matches because the next few lines are optional. It receives the next line, and it checks again and matches, this time with two lines, etc. You would need a final non-optional line so that it doesn't match until it is received, then it will pick up the optional lines if they're present. If you're trying to match a block of text, perhaps having the prompt at the end will do the trick?

BTW, thanks. You're code here solved one of my puzzles by getting rid of a multistate trigger.
_________________
.geniusclown
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Mon Aug 29, 2011 3:04 am   
 
I don't think it should work this way. It gets the first line, and it matches the first, ignoring the rest because the next few lines are optional. Right away, I want to scream bug because it shouldn't ignore the rest, ? is a greedy quantifier that tries to match as much as possible before dropping the optional parts and trying to match with less. But moving on, to what I think is the main bug here...it then receives the next line, but this trigger shouldn't fire again, because the trigger doesn't match 123 alone, the abc part is NOT optional. It's looking back up at the previous line, which was already received and processed earlier, and I don't think it should.
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