Page 1 of 1

Matching unknown second line of multi-line trigger?

Posted: Wed Dec 15, 2010 9:35 am
by Tahlnaith
I'm trying to code some detection scripts for weapon attacks but I can't get any multi-line triggers to work properly. The attack message looks like this.
You slash into yourself's left arm with an ornate steel rapier.
You swing an ornate steel rapier at yourself's left arm with all your might.
The problem is that there's so many ways it can fail, which looks like this.
You slash into yourself's right arm with an ornate steel rapier.
You parry the attack to your right arm with a deft maneuver.
You swing an ornate steel rapier at yourself's right arm with all your might.
You parry the attack to your right arm with a deft maneuver.
So the attack message is the same whether or not the attack actually succeeded, and failure is only indicated if you receive certain messages. You also fire both attacks at the same time, so there's no prompt or other indication in between, and there's a lot of other messages that can pop up right after the attack message that don't mean failure. I've tried making a chain trigger that stays open for one line, and having a single child trigger of ^(.+)$ to capture that second line, and I would use find() to detect if that second line contained failure messages or not. However, the ^(.+)$ message also fires on the attack message itself. So, with this script in the child trigger

Code: Select all

if matches[2]:find("parry") then
	echo(" FAILURE!")
else
	echo(" SUCCESS!")
end
it comes out like this.
You slash into yourself's right arm with an ornate steel rapier. SUCCESS!
You parry the attack to your right arm with a deft maneuver. FAILURE!
You swing an ornate steel rapier at yourself's right arm with all your might. SUCCESS!
You parry the attack to your right arm with a deft maneuver. FAILURE!
Which means that any code I put in the 'FAILURE!' section will fire no matter what, instead of what I want it to do, which is only if the line immediately after the "You slash" or "You swing" message does NOT contain the word "parry". And because there's so many possible messages that can come right after the hit message, I can't really use exact matches.

I have made successful systems for this using an annoying system of variables and not processing the detection of the hits until the prompt, but these always end up very buggy and are difficult and time consuming to code. Is there an easy way of doing this using multiline or chain triggers?

ETA: Here's another way I tried that didn't work. ONe trigger, with the first line set to ^You slash into yourself's right arm with an ornate steel rapier.$ and the second line ^(.+)$, multiline / AND checked with a delta of 1. The script is showMultimatches(). This is the result.
You slash into yourself's right arm with an ornate steel rapier.
-------------------------------------------------------
The table multimatches[n][m] contains:
-------------------------------------------------------
regex 1 captured: (multimatches[1][1-n])
key=1 value=You slash into yourself's right arm with an ornate steel rapier.
regex 2 captured: (multimatches[2][1-n])
key=1 value=You slash into yourself's right arm with an ornate steel rapier.
key=2 value=You slash into yourself's right arm with an ornate steel rapier.
-------------------------------------------------------
You parry the attack to your right arm with a deft maneuver.
Again, the ^(.+)$ matches the FIRST line. The second line with the parry message is completely ignored.

Re: Matching unknown second line of multi-line trigger?

Posted: Wed Dec 15, 2010 10:18 am
by Heiko
The multi state machine is greedy i.e. it tries to match as many conditions as possible on the same line. Note that our multi state machine is much more powerful than a normal multi line regex approach.
To get what you want you'll need to use line spacers to force the second pattern on a new line.
pattern1
line spacer 1 line
pattern2

Re: Matching unknown second line of multi-line trigger?

Posted: Wed Dec 15, 2010 10:22 am
by Tahlnaith
I managed to get something that seems to work well so far by using the parent/child chain trigger approach and setting filter to on in the parent trigger. For future reference though, what do you mean by line spacer?

Re: Matching unknown second line of multi-line trigger?

Posted: Wed Dec 15, 2010 10:26 am
by Heiko
line spacers are a special condition/pattern type "line spacer" that can be selected just like regex, substring, Lua condition etc.