multiline AND triggers: how to do them?

Post Reply
Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

multiline AND triggers: how to do them?

Post by Caled »

You ease yourself out of the Dragon stance.
Advisors' court.

On the first line, I already do:
setStance("disabled")

IF that line is immediately followed by a line (any line) of that colour, I wish to do:
setStance("nostance")

I can't work out how to do that. I can't actually get multiline triggers to work at all, but I don't really understand the process to making one. The sample packages and manual don't help me, because the sample packages seem to only deal with re-examining the same line, while the manual tells me what I already know - that I need a multi-line AND trigger. It doesn't tell me the steps I need to go through to make one, or show me what it will look like in the script editor when complete.

Ryan
Posts: 10
Joined: Mon Jun 22, 2009 1:15 am

Re: multiline AND triggers: how to do them?

Post by Ryan »

This is a perfect example of what I just requested in the feature requests thread. Here's how I'd solve this problem.

Set the multiline/AND option for the first trigger and leave line delta as 1. Add a second condition as a Lua function: return line ~= "You ease yourself out of the Dragon stance."

Then create a second trigger that fires on the right line colour, and have that trigger do: setStance("nostance")

What's happening is this: the first condition of the first trigger will fire when it sees you ease yourself out of Dragon stance. That trigger then moves to the second condition, and tests that condition against the same line. Since the variable 'line' holds the last line received from the MUD, and that last line was you easing yourself out of stance, the second condition will obviously fail on that line. But the second condition will be checked against the next 'line delta' number of lines--in this case, one--and succeed on that line (unless you get that same line twice in a row). When it succeeds, it passes the line it on which it succeeded (the second line) to its children. If that line is the right colour, the second trigger fires and you're good to go. If not, no harm done.

I suspect you don't want this trigger to work only for Dragon stance, however. If you have any wildcards in the intial pattern ("^You ease yourself out of \w+ stance.$" for instance), you'll need to change the second condition to: return not string.match(line, "You ease yourself out of ")

You can add regex-type wildcards to string.match patterns ("You ease yourself out of %w+ stance.$"), but I don't think it's worth bothering with those unless the pattern begins with a wildcard.

Post Reply