About Us
Products
Purchase
Downloads
Support
Forums
Contact Us
Site
 Register to post in forums, or Log in to your existing account
 

 Related 
Contents
References
  Menu Reference
  Command Reference
  Function Reference
  Predefined Variables
  Expressions
  Pattern Matching
  [vNum]
  Command List
Related Links:
  Introduction to Triggers
  Overriding the Mapper
  TriggerStatesTab
  Trigger Options
  Trigger Testing
  Trigger States
  #TRIGGER
  %grep
  Predefined Variables
  Expressions
Pattern Matching [[zmud_Pattern_Match]] 
Pattern Matching


Patterns can contain several special character for wild-card matching.
*            match any number (even none) of characters or white space

?            match a single character

%d            match any number of digits (0-9)

%n            match a number that starts with a + or - sign

%w            match any number of alpha characters (a-z) (a word)

%a            match any number of alphanumeric characters (a-z,0-9)

%s            match any amount of white space (spaces, tabs)

%x            match any amount of non-white space

%y            match any amount of non-white space (same as %x but matches start and end of line)

%p            match any punctuation

%q            match any punctuation (same as %p but matches start and end of line)

%t            match a direction command

%e            match ESC character for ansi patterns

[range]      match any amount of characters listed in range

^            force pattern to match starting at the beginning of the line

$            force pattern to match ending at the end of the line

(pattern)      save the matched pattern in a parameter %1 though %99

~            quote the next character to prevent it to be interpreted as a wild card, required to match special characters

~~            match a quote character verbatim

{val1|val2|val3|...} match any of the specified strings can not use other wildcard inside this

@variable match any of the specified strings or keys works with string lists and record variables

{^string}      do not match the specified string

&nn      matches exactly nn characters (fixed width pattern)

&VarName      assigns the matched string to the given variable (see below for more info)



To save any part of the pattern to the %1..%99 parameters, enclose the part of the parameter in parenthesis.

In specifying a range, you can list specific characters such as [abc] or you can use a range [a-c].

To use a wild card character in the pattern string itself, precede the special character with the ~ quote character. For example, the pattern ~[test~] will match the string [test] rather than being interpreted as a range wild-card pattern. Note that the quote character can be changed in the Preferences section.

To match a blank line, use the $ pattern by itself. To match multiple lines include $ in the middle of the pattern to match the line boundary.

You can also include variables in your pattern, and the name of the variable will be replaced with its value before the pattern match is performed.

Using &VarName

The &VarName syntax deserves a bit more explanation. It is used to store a matched pattern into a variable directly. For example, if you have a trigger:

#TRIGGER {You get &Gold coins}

and the MUD displays

You get 1000 coins

Then the value 1000 is automatically put into the @Gold variable with no further action on your part. By default, the &VarName uses the * wildcard. To specify a different wildcard, insert the wildcard just after the & character. In the above example, when the MUD says

You get many coins

the @Gold variable would then contain the string "many". To restrict the trigger to just match numbers, change the trigger to:

#TRIGGER {You get &%dGold coins}

Now the "You get many coins" will not match the trigger. You can use any of the wildcard specifiers, and can also use the square brackets [] to define your own wildcard range.

Sometimes there is alphabetic text in the pattern after the string you want to capture. To delimit this from the variable name, place the variable name in {} brackets. For example, to capture

You have 1000gp

you would use a trigger:

#TRIGGER {You have &%d{Gold}gp}

which will only match digits and will properly set the @Gold variable to 1000.

The &VarName syntax also works with database records and record variables. If you have a record variable @char and want to set the Gold property, you would use a trigger of:

#TRIGGER {You get &char.Gold coins}

To set the Gold field of record 7 in the database, you would do

#TRIGGER {You get &7.Gold coins}

To set the Gold field of the current database record, leave out the record number all together with the trigger

#TRIGGER {You get &.Gold coins}

This syntax along with the database provides a powerful way to capture information from the MUD.

NOTE: The patterns matched by the &VarName syntax still count towards the %1..%99 variables and can still be accessed in that manner. So, in the example:

#TRIGGER {Hp: &HpVar Mana: &ManaVar} {#SHOW %1 %2}

it will automatically set the @HpVar and @ManaVar variables, and the %1 and %2 parameters will also still be set just as if you had put parenthesis around the &VarName. This is important when you mix &VarName and () in the same trigger. Always count the &VarName as if it also has a parenthesis around it.
Viewer Comments [0 - Post your comments]

Jump to:  

© 2009 Zugg Software. Hosted by Wolfpaw.net