Page 1 of 2

Help with triggers containing "wildcars"..

Posted: Fri Aug 11, 2017 11:58 am
by Don Dalgas
Hi,

Hope someone can help me with correctly creating af trigger containing a wildcard.

Here is an example :

You punch dwarf magician in the head doing unspeakable damage.

The wildcard in this line is : dwarf magician

This is what I have done:

You punch (.*) in the head doing unspeakable damage.

I want this line to trigger the color blue. But the only word in the line that triggers the color blue is actually the "wildcard" - in this case dwarf magician.

What am I doing wrong?

In the "options" to the right of the trigger line I have chosen "Perl Regex".

Thanks in advance.

Re: Help with triggers containing "wildcars"..

Posted: Fri Aug 11, 2017 3:42 pm
by Jor'Mox
I don't know what code you have the trigger using, or if you are just using some sort of trigger option for coloring, but for what you want to do, I would disable any trigger options that are changing color, and then use this as the trigger code:
Code: [show] | [select all] lua
selectString(line,1)
fg("blue")
resetFormat()
That will select the entire current line (if you make changes to it before this, then you would need to use getCurrentLine() in place of just line), change the foreground color to "blue" (or whatever color name you prefer, so long as it is in the list of colors in Mudlet's color table), and then reset formatting so that the next bit of text that Mudlet prints for you doesn't have the same color.

Re: Help with triggers containing "wildcars"..

Posted: Fri Aug 11, 2017 8:28 pm
by Don Dalgas
Thank you for your answer!

Im not familiar with coding at all - so to be honest your answer doesn't make that much sense to me.
It was only by searching the Mudlet manual and the web that I found out how to use the (.*) symbol as a placeholder.
And it works mostly - just not in examples like the one I wrote above.
I was hoping the answer was something like I needed to write something else - or add a sign somewhere - or something.
Years ago I used the MushClient, and in there you could easily make triggers with wildcards just adding a * in the sentence as the wildcard. No problem.
It can't be true that something basic like that shouldn't be possible in Mudlet too?

Re: Help with triggers containing "wildcars"..

Posted: Fri Aug 11, 2017 11:08 pm
by Jor'Mox
Okay, so, the style of trigger pattern writing that you are talking about is simpler, but less powerful. Mudlet COULD have included such a style, but opted not to, in favor of more flexibility. Granted, they have multiple pattern options, so in theory they could have added the simpler style as an additional option. You may want to recommend it as a feature to add.

Regarding the original question though, I wrote out the code for you, specifically so you wouldn't need to actually know anything about coding in order to use it. Just expand the code box, copy all three lines, and paste them in the big white box at the bottom of the trigger you are working on. Given that you aren't going to be doing much code wise in other areas, the bit after the code box is largely irrelevant for your purposes.

Re: Help with triggers containing "wildcars"..

Posted: Sat Aug 12, 2017 7:09 am
by Vadi
You don't even have to use (.*) is pretty similar to * and doesn't confuse everyone who knows (.*) ;)

Re: Help with triggers containing "wildcars"..

Posted: Sat Aug 12, 2017 12:26 pm
by Jor'Mox
No offense Vadi, but generally the simplified trigger patterns also come with simplified incorporation of captured text, dramatically improving the ability for the coding impaired to create their own aliases and triggers. Here is an example similar to what I have seen people try to do for an alias:

Pattern: c * *
Substitution: cast '%1' %2

And this is what they MEANT (in case it wasn't clear)
Pattern: ^c (.*) (.*)$
Code: send("cast '" .. matches[2] .. "' " .. matches[3])

Personally, I feel that allowing the simplified regex type for both aliases and triggers, along with allowing the use of captures in substitution/send plain text for aliases/triggers would be a huge improvement for those who are more familiar with other MUD clients, and especially those who aren't particularly comfortable with coding.

And, while the * syntax could potentially be confusing, there are other options available, that wouldn't necessarily be so confusing, though from what I can tell, * (along with some other simplified options) is used by both MUSHclient and cMUD, which represent the two clients other than Mudlet that I hear people using most often.

Re: Help with triggers containing "wildcars"..

Posted: Sat Aug 12, 2017 12:35 pm
by Vadi
I'm all for making Mudlet more accessible, but I'm not sure of the value on that - they only did it because they've learnt it elsewhere. If a newbie starts with Mudlet, they wouldn't learn this.

Instead, we could make it easier to learn by providing some sort of a tutorial right within the client. https://github.com/Mudlet/newbie-tuts is an idea in that direction. I think that'll be a more worthwhile investment of development effort.

Re: Help with triggers containing "wildcars"..

Posted: Sat Aug 12, 2017 12:54 pm
by Jor'Mox
Even if you didn't want a simplified pattern matching option, allowing the use of matched text in the substitution fields still seems like a good idea, as it allows for the most simple, and probably the most common, use of both triggers and aliases to very easily and intuitively incorporate capture groups.

Also, given that this is a pretty common pitfall that I have encountered when trying to help people make aliases, I think having an option or something that is on by default that automatically adds the ^ and $ to an alias pattern would be nice. While triggers frequently don't capture a whole line, it is exceedingly rare to find an alias that isn't meant to do so, and it is all too common to see people accidentally trigger an alias while trying to do something entirely unrelated (like someone casting a fireball when their "ff" alias gets triggered by them trying to say "off" in a sentence).

Re: Help with triggers containing "wildcars"..

Posted: Sat Aug 12, 2017 2:31 pm
by Vadi
Those are good ideas! Mind suggesting it as an improvement on https://github.com/Mudlet/Mudlet/issues/new ?

Re: Help with triggers containing "wildcars"..

Posted: Tue Aug 15, 2017 12:38 am
by SlySven
To the original poster it might be worth pointing out the meaning of (.*):
  • the single '.' means match a single character no matter what (space, number, letter, punctuation) it is {although dealing with non-ASCII characters in the future as we will have to support for Mudlet 4.x makes working out what a character is a little more interesting!}
  • the following '*' means match the preceding thing ("a single character" remember) one or more times - so means if there is anything there it gets matched
  • the surrounding '('...')' means whatever they embrace is captured as a group (and thus gets made available in the related script in the global lua array (a.k.a. table) called "matches" at index of 1 + the total count of '(' found so far reading the regular expression from left to right {if the whole trigger pattern is a "match" then the whole line is stored in the first item in the "matches" table (i.e. matches[1])})
In conjunction with the surrounding "You punch "..."in the head doing unspeakable damage." you can see that what ever is in the ... position gets captured and stored as "matches[2]". Now the "highlight" option in the trigger editor has to be robust but necessarily is a bit dumb and only highlights the areas that are marked as something to capture - so a quick and dirty fix is to nest one explicit capture inside another with a pattern of:

(You punch (.*) in the head doing unspeakable damage.)

However you will need to increase the number used to get the victim from matches as it then becomes matches[3] - as you are now explicitly capturing the whole line because of the outer '('...')'s that flags all of the line to be highlighted... :D

I had this issue too a while back but this is what I worked out as a fix... :geek: