Triggers with an exception

Posted by Helio on Mon 15 Jul 2002 07:14 AM — 10 posts, 29,704 views.

#0
Hi, i was wondering if it was possible to have a trigger that would go off for everything except for one variable.
currently i have a trigger to go off when there is an output like "Without warning XXX stabs you from behind!"
with XXX being anything. Is it possible for me to have the trigger not go off when XXX is say "Orc" but still go off for everything else?
Australia Forum Administrator #1
Probably the simplest way is to make the trigger that matches everything, eg.


Without warning * stabs you from behind!


Then make the trigger call a small script subroutine that excludes the exception, and takes action otherwise. eg.


sub stabtrigger (sname, sline, wildcards)

if wildcards (1) = "Orc" then 
  exit sub
end if

world.send "attack " & wildcards (1)

end sub
Australia Forum Administrator #2
Even simpler, have two triggers, and make them have different sequences. eg.



(sequence 90)

Without warning Orc stabs you from behind!


This trigger does nothing.


(sequence 100)

Without warning * stabs you from behind!


This trigger does what you want to do.
#3
Thanks dude!
You rock!
Canada #4
This would also work:

^Without warning (?!Orc)(.*?) stabs you from behind\!$

What I did was take your original line:

Without warning * stabs you from behind!

...Then I clicked the "Convert to Reg. Exp." button, to get this:

^Without warning (.*?) stabs you from behind\!$

...Then I put the pre-qualifier ?! which means NOT and the word you don't want to match, "Orc", wrapped in circle brackets.

I've tested this out using a different trigger line, and it works! The nice thing, no script required. :)
Australia Forum Administrator #5
I thought about doing it with a regexp, but couldn't work out how. :)

The only problem with your idea, Magnum, is it would match on (say) "Orchard" and omit it, whereas the multiple trigger idea (or the script) is specific to the word "Orc".
Canada #6
Actually, Nick, you are wrong. The expression does work as I said. I tested it with this:

<triggers>
  <trigger
   enabled="y"
   match="^You say\: The (?!Orc)(.*?) is green\.$"
   name="Test"
   regexp="y"
   script="TriggerTest"
   sequence="100"
  >
  </trigger>
</triggers>


Sub TriggerTest (N, L, W)
	World.Note "1:  '" & W(1) & "'"
	World.Note "2:  '" & W(2) & "'"
	World.Note "3:  '" & W(3) & "'"
End Sub

Perhaps the reason this works is because the expression is evaluated left to right, and once it encounters a mismatch, it rejects the line immediately without processing the rest. (Actually more efficient).

Indeed, I can understand why you made the statement you did, and I suppose this effect could possibly be considered a bug, if what you wanted is the results that you predicted.

Nah... not a bug. If one wanted the type of results you predicted, they would use ?: instead of ?! like below:

^You say\: The (?:Orc)(.*?) is green\.$

Which with a line like "You say: The Orchard is green." would return "hard" as wildcard 1.

Heh, actually, that's not what you predicted either. Building an expression to do what you expected would be pretty hard. I would only consider the above a bug if what you expected could not be done another way... because then you have a situation which can't be resolved.

I've spent enough time on this for now. Sorry, I'm not in the mood to try and build a trigger to do what you expected mine to do... Perhaps another time. :)
Canada #7
Gah!!!! I'm being an idiot lately...
I re-read my post after submitting it, and realize I misinterpreted what you said (I think).

You mean it will reject "Orchard", when the user would probably want that to be accepted.

In that case, yes, you are right... and offhand I can't think of a way around that either, and as I just said, I don't feel like doing more research into this right now.
Canada #8
Heh... I couldn't let it go. This works instead of the original expression I offered:

^You say\: The (?!Orc )(.*?) is green\.$

...since you look for the extra space in the disqualifying section of the expression.

To disqualify multiple strings, you could do something like this:

^You say\: The (?!Orc |Bear )(.*?) is green\.$
Australia Forum Administrator #9
Quote:

You mean it will reject "Orchard", when the user would probably want that to be accepted.


Yes, that is what I meant. I assume he wanted the actual word "Orc" only to be rejected. However, your later post seems to fix that very nicely. Thanks.