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

 Related 
Contents
Whats new in v3
  New commands
  New functions
  New Mapper
  Script Wizard
  Pattern Wizard
  Stringlists / Tables
  GMCP Support
  SQL Scripting
Related Links:
  Whats new in v3
Pattern Wizard [[pattern_wizard]] 
A new wizard/ Trigger Pattern Wizard has been added to help novice users create complex trigger patterns with wildcards. The GUI allows you to select a line from the MUD to match, then highlight the parts of the line that might change and convert them to proper wildcards. Help tips for regular expression triggers are also provided, along with a robust pattern tester to determine if your trigger matches text from the server.

This screen is only shown by default when the View/Use Script Wizard option is selected. Turn this off to show the normal "Script Text" tab instead. You can freely switch between the "Script Text" tab and the "Pattern" tab when editing a trigger to use the Pattern Wizard.

At the top of the Pattern Wizard, the normal pattern for the current trigger is shown. You can use the Pattern Wizard as a simple Pattern "Tester" by selecting a line of text from the server using the "Text" drop-down menu, or by typing directly into the Text field. As you type, the wizard will automatically display whether your pattern matches the text or not.

Creating Patterns

The true power of the Pattern Wizard comes into play when you are creating a new pattern from scratch. Many novice users have no idea how to use wildcards or regular expressions to create a trigger that matches text that can change. Using the Pattern Wizard makes this very easy and also helps teach new users how wildcards work.

To create a new pattern, first create a new Trigger and be sure the "Pattern" tab at the bottom of the editor is selected. Next, click the orange "Text" drop-down menu to select a recent line sent from the server that you want to match. Or just type the sample line from the server into the Text field manually. For this example, we will enter the text "You get 120 coins" into the Text field. When you are done entering the text, press Enter as instructed.

When you press Enter (or when you select a line from the server), your sample text will be copied automatically into the Pattern field at the top. This is your starting pattern with no wildcards. This pattern will only match this exact line from the server.

As instructed by the wizard, use your mouse to select the portion of the text that can change. In this example, the "120" number can change, so highlight that text in the Text field (or highlight it in the Pattern field...either way works).

When you highlight some text, a drop-down "Match" field will be highlighted in the main part of the editor. It tells you to "select the type of match from this list". In this case, we want to "Match any digits", so select that from the drop-down list. You'll notice that the "120" in the Pattern field will now change to "%d" to indicate it is using the wildcard to match any digits.

You can continue selecting text that changes and use the Match drop-down to select the proper wildcard type. Each different selection will be assigned a different color so you can match the colored wildcard in the Pattern with the corresponding text in the Text field.

In our example, we also wish to save the matching number to the %1 variable, so click anywhere in the orange %d or 120 field and then click the checkbox called "Save captured subpattern". This will cause () parenthesis to be added around the %d and will show "%1: 120" in the list of subpatterns on the right. The list of subpatterns on the right is useful for when later writing your script since you'll know that the %1 variable has the "120" value.

To give your captured subpattern a name other than %1, enter it into the "Name" field. For example, we enter "coins" (without the quotes of course) into the Name field. As we type the name, the %1 in the captured subpattern list will be changed to our name, and you'll see the "$coins:" name added to the pattern in the top Pattern field.

Finally, we can use the checkboxes for "Force match at start of line" and "Force match at end of line" to add the ^ to the start of the pattern or the $ to the end of the pattern. In this case, we check the "match at start of line" box.

Our result is the trigger pattern: ^You get ($coins:%d) coins
We created this without any knowledge of wildcards or regular expressions. We can now use the $coins variable in our script to act upon this line from the server.

Merging Text

The power of the Pattern Wizard doesn't stop there. One advanced feature is the ability to take multiple lines of text from the server and automatically determine the appropriate wildcards.

For example, create a new trigger and enter the text: "You get 120 coins" into the Text field and press Enter. Instead of pressing Enter, you can also click the Up-arrow button to the right of the Merge button to copy the current Text value into the Pattern field. Clicking the Down-arrow will copy the current pattern into the Text field but will replace wildcards with actual sample text.

Once you can copied the text field into the pattern, now enter the new text "You get 9999 coins" into the Text field. But instead of pressing Enter, click the Merge button. You'll see the "120" in the pattern field automatically change to "%d". When merging multiple lines of text into the pattern, the wizard will choose the least "greedy" wildcard for matching all of the merged line.

For example, now enter the text "You get 9999 gold" into the Text field and click Merge. Now the "coins" in the pattern will be changed to %w to match any word.

No other MUD client or even any regular expression "wizard" offers this type of "Merge" feature. It is unique to CMUD and one of the easiest ways for novice players to create triggers that match text from the MUD that changes. Just select a bunch of sample lines from the MUD and keep merging them together.

Other features

To the right of the Merge button are Undo and Redo buttons. These can be used to undo any changes made to the trigger pattern. An unlimited level of "undo" is provided. So any time you get into trouble, just Undo it.

At the very bottom of the wizard, a line will be displayed showing the corresponding Regular Expression pattern. This is for advanced scripters who understand regular expressions. CMUD uses this regular expression internally to match the text sent from the MUD. A clipboard button is provided to copy this regex into the clipboard.

Clicking the More Help on Pattern Matching link will open the help file topic for wildcard pattern matching.

If you change the trigger type to Regular Expressions in the More options panel, the Pattern Wizard will be replaced by simple regular expression tips. You can still test the pattern by selecting text from the server or entering text manually. But you cannot create regular expression wildcards nor can you use the Merge button for regular expressions.

If you switch from a Pattern trigger to an Alarm trigger, the wizard will simply show some tips on creating an alarm pattern.

NOTE: When expanding the More/Less option panel at the bottom of the trigger editor, the wizard might not have enough screen space to display itself properly. Either close the panel by clicking the Less button, or resize the editor window to make it large enough to display the wizard.
Viewer Comments [0 - Post your comments]

Jump to:  

© 2009 Zugg Software. Hosted by Wolfpaw.net