Triggers

Posted by Matthias on Mon 08 Sep 2003 03:02 AM — 9 posts, 28,181 views.

#0
I think there should be a sort of Mass trigger entering system, like:
If you match any of these:
You feel your muscles lock up.
You cannot do that, you are paralyzed.
Your muscles stiffen up.

Then enter:
eat bloodroot
Russia #1
You can do just that with regular expressions:

^(You feel your muscles lock up\.|You cannot do that, you are paralyzed\.|Your muscles stiffen up\.)$

That'll make a trigger which will match on any of the options in parenthesis. There's a file named RegularExpressions.txt in your Mushclient/Docs directory that explains the syntax and general rules of using regular expressions. But in brief the meaning of the above is:

^ - denotes the start of line
$ - denotes the end of line
\ - an escape character, it's needed in this case because '.' means any character in RegExp
() - denote what should be captured as a wildcard, and serve for grouping
| - a "switch", ^(a|b)$ will match on either 'a' or 'b' but not on 'ab'.
#2
So if I wanted to put a wildcard in there, would I just put the normal * for that? or is it different for the Regular expression thing? (whatever that is)
USA #3
in a reg exp, a * is 1 or more of the previous character, so a * in a normal trigger becomes a .* in a reg exp (. being the wildcard character)

Can read about it in the VB/Java (windows script) Documentation, links are on the top of the forum
#4
So, is an escape character used to indicate not to interpret a symbol as a reg exp? So for a wildcard, I'd do something like this:
^(/* brings /* arms crashing down on you/.)$
, right?
USA #5
Well, if you switched the slashes to backslashes...
That would match on the line....
* brings * arms crashing down on you.

But, if you want something infront of the asterix (which arent variables, just the asterix) youd need to either get rid of the ^ (start of the line) OR add a .* in between the ^ and the \*

Also, if you wanted the parenthesis to be included, you would need to escape them.
Australia Forum Administrator #6
Try entering this in a trigger:

* brings * arms crashing down on you.

And then click on "convert to reg. expression" - that will show the differences.
#7
Umm, I'm not really sure what I'm doing wrong... I have the trigger set to match this...:
^(\*You have a particularly intense shiver\*|\*maw and exhales a blast of frigidly cold air on you\*|\*You feel the strength ebb from your body as the cold takes its toll\*|\*raises a hand towards you and blasts you with cold, frigid air\*|\*Your body slows as it freezes in the extreme cold\*|\*sends the cold of the grave\*|\*The bubonis entity sinks its teeth into you, and begin shivering\*)$

And to send this:
apply caloric

But it won't match... what am I doing wrong? (That matching above was one of the shorter ones :p)
Russia #8
You seem to be still confused about the wildcards in regexp's. Here, by doing '\*' you are actually telling the client to match on, for example:


*You have a particularly intense shiver*


this is the literal string that your trigger will match on. It won't match on something like:


3245h, 1256m cexkdb-You have a particularly intense shiver.


The reason for this is that you are using an escape character ('\') before an asterix, which itself is a special character denoting any number of whatever precedes it. However, when escaped with '\' any special character is interpreted literally. So to cut the long story short, in order to match on:

3245h, 1256m cexkdb-You have a particularly intense shiver.

you'd need to use wildcards, and a basic wildcard in regexp is denoted by '.' (period). There are other types of wildcards but this one works in all cases. The most basic form of a wildcard in regexp looks like:


.*


which tells the client to match on any number of anything.
Thus, you could amend your trigger to include:


.*You have a particularly intense shiver.*


To reiterrate on the meaning of the escape character using the above example - if you actually wanted to include the period at the end of the above line (the actual period in the end of the sentance), instead of a wildcard that would match that period among other things, you would do:


.*You have a particularly intense shiver\.


By prepending an escape character to a special wildcard character '.' you are stripping any "specialness" off the latter and turn it into a simple literal, just like any letter in the string >You have a particularly intense shiver". Hope that makes sense. As Nick suggested, one of the best ways to figure out the basic regexp syntax is to use Mushclient's 'Convert to regular expression' option in the Add Trigger dialogue, that will take your trigger (normal one, without any special syntax, like "*You have a particularly intense shiver*") and turn it into a corresponding regexp, showing you how the syntax works. Although that provides only the minimum functionality of regexp, it can be very useful when just starting out.