Is there a way to keep evaluating on a line another trigger matched, but without evaluating the segment of text that was already matched? If it helps, this is specifically what I'm trying to do:
Swinging a brutal war hammer in an underhand arc, Murphy strikes at you. You double over and can barely breathe from the force of your belly being smashed.
In this I match "^Swinging (.*?) in an underhand arc\, (\w+) strikes at you(\.|\,)" and then trigger that to activate a trigger that matches "double". Then here:
With a focused look, Icarus strikes at you with a crimson double-chained taurian flail. You are cuffed lightly in the side of your face.
I match "^With a focused look\, (\w+) strikes at you with (.*?)(\.|\,)" and this activates "cuffed".
The basic idea of this is, "cuffed" and "double" and a ton of other one word triggers are activated in a group on initial attack messages like the one I described. This is necessary because the variation in names and weapon names make linebreak locations unpredictable.
Now here's the problem, I can pick out whatever single words are unique to each attack message and match them because these messages never change, but the weapon names can and do change and it gets messy when your one word trigger matches on the weapon name. My example here is "double" and "a crimson double-chained taurian flail". When that attack paragraph hits me I match "double" when I want to match "cuffed".
So, back to my question; can I exclude part of a line from further evaluation without excluding the whole line?
... can I exclude part of a line from further evaluation without excluding the whole line?
Not as such, in the standard interface, no.
However there are a couple of approaches you could take. For one thing you can do an "or" in a regular expression, like this:
You (are doubled up|laid low|knocked senseless)
Another approach is to simply match everything, and then in trigger processing do another regexp on the 2nd part (using Lua regular expressions, or the PCRE ones supplied in the Lua rex library).
Quote: Could you make it match "you double" and "you are cuffed" instead?
No, because a linebreak might show up between "you" and "double". I could make it match "you( |\n)double" but I don't want to to do that if there's a cleaner way of doing this. Besides, what if I get hit with a you double flail? :)
Quote: Another approach is to simply match everything, and then in trigger processing do another regexp on the 2nd part (using Lua regular expressions, or the PCRE ones supplied in the Lua rex library).
I don't completely understand this, but it looks like a possibility. Is there a way to do this with Python?
I remember that thread. Wish Lusternia had a config wrapwidth 0 option.
I'm pretty comfortable using Muschlient itself, but coding is another matter. I can do some fairly basic stuff with Python, enough for "auto-curing", but I don't even know what parsing is. If you give me the general idea on how to parse, I think I can figure it out.
Question though. If you already know which lines activate which responses, then why fuss with making a separate set of triggers to match what you know is coming?
Sorry, if I'm misunderstanding that or there's more to it.
Ok, odd possible solution.
"Swinging (.*?) in an underhand arc\, (\w+) strikes at you."
Set that as your trigger to match the first bit and grab the weapon and person name. The (\.|\,) isn't really necessary in here, but is necessary in other instances, unless a : or other similar single character also could appear and you don't want it matching on that.
Place %1 and %2 in a variable call them something like weapon and vicName
"^(?<=(Swinging @weapon in an underhand arc\, @vicName strikes at you.)|)(.*)double"
Set that as the trigger that's activated. The variables are necessary because all lookbehind or lookahead assertions must be fixed length so (.*) creates errors.
You can use more ors to add on more statements that could result.
(ie.^(?<=(Swinging @weapon in an underhand arc\, @vicName strikes at you.|With a focused look\, @vicName strikes at you with @weapon.|)(.*)double
This second trigger will match on:
Swinging a brutal war hammer in an underhand arc, Murphy strikes at you. You double over and can barely breathe from the force of your belly being smashed.
or:
double over and can barely breathe from the force of your belly being smashed.
or even just:
double
I simply wonder if the setvariable function would work before the line is matched again.
Sorry if it wasn't clear, but there's way more than one result for each attack. That's why I activate the one word triggers in a group. And the (\.|\,) is necessary because you might get hit with something like this:
With a focused look, Kurt strikes at you with an elongated scimitar with etched webbings, and you partially parry the blow with a loboshigaru rapier. Kurt strikes your right leg, striking a major artery which splurts blood in all directions.
Notice the "," where a "." was. I'm not sure, but I think a small or would be faster than a full wildcard.
I had to think about it. With the (.*?). the regexp gets confused and doesn't know what to capture, so it must be (.*?)(\.|\,) to let it know there's a period or comma there to stop catching the weapon name.
However, in use of the lookbehinds, the . suffices and would be faster in the long run, though no human could notice the difference.
Alright, turns out Python does have regular expressions, so now I'm capturing the second part of the attack in one big wildcard. However, it seems Mushclient doesn't like it when you try to use a string with newlines in a script function. Here's the error message:
EOL while scanning single-quoted string
Anything I can do about this?
EDIT: Actually, it's not just if I try to use it in a script function, I can't do anything at all with it.
Are you doing "send to script"? That is, scripting in the trigger itself? It wouldn't surprise me if you have problems with multi-line triggers, because if you do something like this:
line = "%0"
And if %0 has a newline in it, it will expand out to be:
line = "With a focused look, Icarus strikes at you with a crimson double-chained taurian flail.
You are cuffed lightly in the side of your face."
Now in many script languages this will be an error because the literal string is not terminated before the newline.
However if you call a script function (put a name in the "script" box) then in side the script function you can use a variable name, and you won't have the problem.
Yes, I was calling my script function using send to script in the trigger. Unfortunately, this is the only way I can get the wildcard I want, as it's the 28th, and I'm not using Lua so I only get the first 10.
Is there a way to change which wildcards get sent in the third variable?
EDIT: Nevermind, I tried it and somehow wildcard 28 became wildcard 9, so it works. Thanks for all the help, I appreciate it.
That works even better, since it seems wildcard 10 (Python starts counting a list at 0, so it would look like 9) contains all the text that was matched, rather than a specific wildcard. Thanks again.
In the early days of MUSHclient, there were 9 wildcards, and the 10th was reserved for the entire matching line. This caused a problem when the number of wildcards was increased, so the function GetTriggerWildcard was introduced to allow you to get the other ones.