Page 1 of 1

How do I create an Ansi/Color Trigger to capture multiple values.

Posted: Sat Apr 20, 2019 12:40 pm
by jieiku
here is the output I am trying to create a Trigger for:
2019-04-20_05-51.png
2019-04-20_05-51.png (9.34 KiB) Viewed 6811 times
Initially I had a trigger with a pattern like this:

Code: Select all

^You still have to kill \* (.*) \((.*)\)$

aard.qTarget = matches[2]
aard.qLocation = matches[3]
This worked fairly well in most cases, but there are some situations where it does not one I recently ran into was parenthesis being part of the room name:
2019-04-20_05-31.png
2019-04-20_05-31.png (1.59 KiB) Viewed 6819 times
The outer set of parenthesis are always grey, and anything inside of them that is cyan is part of the room name, so I figured an ansi trigger would solve this.

In cMud you would specify the ansi color '%e[1;36m as part of the pattern directly into the pattern field such as:
*group-*'%e[1;36mI've rolled a 100 sided dice 1 times, the total result is: %e[1;34m(%d)%e[0m'$

Here is what I have so far:
2019-04-20_05-37.png
2019-04-20_05-37.png (37.67 KiB) Viewed 6819 times

The problem is it matches the entire line, I expected multimatches[4][2] to only match the Green Mob name:
2019-04-20_05-03.png

Also I could not find the documentations or examples for creating a complex ANSI trigger like this, I was working from this as a reference: https://forums.mudlet.org/viewtopic.php?t=4771

If I can manage to get this working I would be happy to add some examples to the wiki.

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Posted: Sat Apr 20, 2019 2:15 pm
by jieiku
So part of the problem was I broke the original pattern into its individual pieces.

I did this because I thought I needed to have each regex pattern following its color trigger section Thats why the opening post I have 10 lines for my patterns. It is actually much simpler, you just use the complete Regex pattern, and also use a color trigger for the parts you want to capture that match a particular color.
2019-04-20_07-08.png
2019-04-20_07-08.png (30.07 KiB) Viewed 6797 times
I was able to figure out that this is how this works after discovering the function showMultimatches()
2019-04-20_07-13.png
2019-04-20_07-13.png (15.22 KiB) Viewed 6797 times

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Posted: Sat Apr 20, 2019 4:08 pm
by jieiku
I am now left with a question.... What if I want to mach on the grey color (The outer Parenthesis on the Location), and capture what is between?

I am now matching the grey color:
2019-04-20_09-02.png
2019-04-20_09-02.png (22.43 KiB) Viewed 6789 times
I want to use a color trigger to detect which parenthesis are the grey outside parenthesis, and then capture everything in between.

That way if a Room or Area is in a different Color or multiple colors. the Trigger would still match / work, as far as I know I have only ever seen the outer parenthesis that contain this value in grey, but the value within may occasionally have color.

Is this something that is possible?
2019-04-20_09-05.png
2019-04-20_09-05.png (24.13 KiB) Viewed 6789 times

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Posted: Sun Apr 21, 2019 4:16 am
by Vadi
Isn't it multimatches[3][1] ?

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Posted: Sun Apr 21, 2019 8:04 am
by jieiku
In this case it is multimatches[3][1] "A catwalk overlooking the exercise yard" But it only matched because the entire room name is cyan.

Occasionally the roomname is different colors, such as cyan and red, as well as cyan, red and white. Occasionally the room is all red as well.

However the outer Parenthesis are ALWAYS grey, so if I can capture whats between them then it wont matter what color the room is.

The only solution I can think of is that a color match trigger, could also return its position in the string.

so in the above example multimatches[4][2] and multimatches[4][3] returns the outer parenthesis. If it also returned the position in the string(multimatches[1][1]) then you could determine the substring position and length between the two parenthesis.

There is likely more than one way to accomplish this use case. I get the feeling I am just overlooking a feature or something?

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Posted: Sun Apr 21, 2019 10:30 am
by Vadi
Your regex pattern multimatches[1][3] also captures what's inbetween the brackets. Have you got an example where it doesn't?

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Posted: Sun Apr 21, 2019 12:39 pm
by jieiku
Yes, it has trouble when the roomname itself has parenthesis as part of the roomname, which is why i turned to the color triggers:
2019-04-20_05-31.png
2019-04-20_05-31.png (1.59 KiB) Viewed 6754 times
maybe there is a way to rewrite this so that it understand to match on the outer most parenthesis?

Code: Select all

^You still have to kill \* (.*) \((.*)\)$

Re: How do I create an Ansi/Color Trigger to capture multiple values.

Posted: Sun Apr 21, 2019 3:53 pm
by Vadi
Yep - try (.*?), see https://www.rexegg.com/regex-quantifier ... y_solution for more reading!