Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Keep Evaluating problem

Keep Evaluating problem

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Candido   USA  (78 posts)  Bio
Date Sat 15 Jul 2006 04:01 AM (UTC)
Message
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?
Top

Posted by NeoFryBoy   USA  (42 posts)  Bio
Date Reply #1 on Sat 15 Jul 2006 05:16 AM (UTC)
Message
Could you make it match "you double" and "you are cuffed" instead?
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #2 on Sat 15 Jul 2006 05:52 AM (UTC)
Message
Quote:

... 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).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Candido   USA  (78 posts)  Bio
Date Reply #3 on Sat 15 Jul 2006 06:24 PM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #4 on Sat 15 Jul 2006 09:48 PM (UTC)
Message
Ah, the newline-in-the-middle trick. :)

Try reading this lengthy post, it covers much the same material:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6363

In it I suggest that you first break up the incoming text (internally in a script) into one big block of text, remove th newlines, and then parse it.

Quote:

Is there a way to do this with Python?


If Python supports regular expressions, I expect so.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Candido   USA  (78 posts)  Bio
Date Reply #5 on Sat 15 Jul 2006 09:54 PM (UTC)
Message
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.
Top

Posted by NeoFryBoy   USA  (42 posts)  Bio
Date Reply #6 on Sat 15 Jul 2006 10:20 PM (UTC)

Amended on Sat 15 Jul 2006 11:16 PM (UTC) by NeoFryBoy

Message
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.
Top

Posted by Candido   USA  (78 posts)  Bio
Date Reply #7 on Sat 15 Jul 2006 10:33 PM (UTC)
Message
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.
Top

Posted by NeoFryBoy   USA  (42 posts)  Bio
Date Reply #8 on Sat 15 Jul 2006 11:14 PM (UTC)
Message
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.
Top

Posted by Candido   USA  (78 posts)  Bio
Date Reply #9 on Mon 17 Jul 2006 12:16 AM (UTC)

Amended on Mon 17 Jul 2006 02:32 AM (UTC) by Candido

Message
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.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #10 on Mon 17 Jul 2006 05:44 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Candido   USA  (78 posts)  Bio
Date Reply #11 on Mon 17 Jul 2006 04:09 PM (UTC)

Amended on Mon 17 Jul 2006 09:31 PM (UTC) by Candido

Message
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.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #12 on Mon 17 Jul 2006 09:53 PM (UTC)
Message
You can get the 28th wildcard with GetTriggerWildcard:

http://www.gammon.com.au/scripts/doc.php?function=GetTriggerWildcard

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Candido   USA  (78 posts)  Bio
Date Reply #13 on Tue 18 Jul 2006 07:19 PM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #14 on Tue 18 Jul 2006 10:07 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


38,082 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.