Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Triggers with an exception

Triggers with an exception

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Helio   (9 posts)  Bio
Date Mon 15 Jul 2002 07:14 AM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 15 Jul 2002 08:48 AM (UTC)
Message
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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Mon 15 Jul 2002 08:50 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Helio   (9 posts)  Bio
Date Reply #3 on Mon 15 Jul 2002 01:28 PM (UTC)
Message
Thanks dude!
You rock!
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #4 on Mon 15 Jul 2002 06:07 PM (UTC)
Message
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. :)

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #5 on Thu 01 Aug 2002 01:02 AM (UTC)
Message
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".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #6 on Thu 01 Aug 2002 03:45 AM (UTC)
Message
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. :)

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #7 on Thu 01 Aug 2002 03:51 AM (UTC)
Message
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.

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #8 on Thu 01 Aug 2002 04:28 AM (UTC)
Message
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\.$

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #9 on Fri 02 Aug 2002 05:31 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


21,099 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.