Colorizer trigger

Post Reply
Xixity
Posts: 6
Joined: Sun May 24, 2009 3:38 pm

Colorizer trigger

Post by Xixity »

These are the patterns I have colorized:
A scorching wall of fire stands here. ~Substring
There are (\w+) scorching wall of fires here. ~Perl regex

However when I see something along these lines:
A vigilant monk stands here, alert and watchful for enemies of the city. A dark brown root sigil is here. There are 4 scorching wall of fires here.

Only the '4', or whatever number, ends up being highlighted.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Bug: Colorizer trigger

Post by Heiko »

This is not a bug. The colorizer function highlights the entire pattern if there are no capture groups defined in the regex pattern. As substring patterns don't have capture groups it'll automatically highlight the defined substring. If you have defined capture groups (only available for perl regex patterns), the capture groups will be highlighted instead of the entire pattern. This approach makes the whole colorizer function more flexible as you can decide yourself what you'd like to be highlighted.
There are (\w+) scorching wall of fires here. ~Perl regex
Consequently, if you changed above pattern to:

Code: Select all

There are (\w+) scorching (wall of fire) here
both capture groups would be highlighted. Note that you can defined capture groups within groups like:

Code: Select all

(There are (\w+) scorching (wall of fire) here)
This will highlight the entire pattern, but still makes the (\w+) capture group available for your scripts as matches[3]. matches[1] will be the match of the entire pattern, matches[2] will be the first capture group - which is the entire pattern too in this case and matches[3] will be the (\w+) group.

As you have defined 2 different patterns in your pattern list you have created an OR-Trigger with a list of 2 patterns. The trigger will fire whenever one of its patterns is true i. e. if your first pattern matches, the second pattern will not even be evaluated. Consequently, the highlighter function will only highlight your first pattern and the regex pattern will be ignored. If you want both patterns to be evaluated - and thus highlighted - you need to make this trigger an AND-trigger. AND triggers will only fire when all of its conditions (=patterns) are true. To do this, you need to check the "multiline/AND-trigger" option and set the multiline delta approriately. If both patterns should occur on the same line the line delta should be 0. If the second pattern occurs 3 lines later, set the delta to 3. Note that if you are using screenwidth=0 in your MUD settings then the screen lines and the MUD lines may not be identical because of the line wrap.

Xixity
Posts: 6
Joined: Sun May 24, 2009 3:38 pm

Re: Colorizer trigger

Post by Xixity »

Thanks. That explanation really helped me understand the and/ or triggers as well.

Post Reply