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
➜ VBscript
➜ Multiple line parsing
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Indiana
Romania (5 posts) Bio
|
| Date
| Tue 25 May 2004 07:01 PM (UTC) Amended on Tue 25 May 2004 07:03 PM (UTC) by Indiana
|
| Message
| I come acros to a quite interesting problem I still haven't solved.
The text I wish to parse is:
(something)You are:
deaf.
blind.
....
I want this snippet to be triggered and call a VBScript function so that I can parse the next n lines (to actualy modify some variables acording to my script).
I am aware that a simple version would be to actually trigger 'deaf.', 'blind.' and change some variables acording to them but the context is a bit different. It is actually a diagnose and some texts there can be defences as well as afflictions (so I want to be deaf and blind, but not paralysed).
This is why I want to parse all the lines that come after the text 'You are:' and use a function to verify.
Thank you. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Tue 25 May 2004 11:27 PM (UTC) Amended on Tue 25 May 2004 11:29 PM (UTC) by Nick Gammon
|
| Message
| You want a multiple-line trigger. Wade through this posting:
http://www.gammon.com.au/forum/?bbsubject_id=4087
It describes in some detail the design that went into the new multi-line triggers in MUSHclient.
Basically you want to match on something like:
<triggers>
<trigger
enabled="y"
lines_to_match="10"
match="(?x)You\ are:\n ( ( (?P<d>deaf) | (?P<b>blind) | (?P<p>paralysed) ) \.\n )+ <.*>.*\z"
multi_line="y"
regexp="y"
send_to="2"
sequence="100"
>
<send>
deaf = %<d>
blind = %<b>
paralysed = %<p>
</send>
</trigger>
</triggers>
This was an interesting one to get right. What this does is set up a multi-line trigger that matches on "deaf", "blind", "paralysed" (in any order) and puts the results into named wildcards.
If your "send" box you could test them (in a "send to script") like this:
if "%<p>" <> "paralysed" then
if "%<d>" = "deaf" then
send "drink red potion"
end if ' deaf
end if ' not paralysed
The tricky bit was terminating the regular expression. Because it is matching any number of lines that *might* follow it needs a "terminating" line, one that tells it that it is *not* an affliction line. I have chosen something with:
< (something) > (something)
(ie. a prompt line) but you might tailor it to what you actually see.
In fact, after a bit more experimenting, this works better:
<triggers>
<trigger
enabled="y"
lines_to_match="10"
match="(?x)You\ are:\n ( ( (?P<d>deaf) | (?P<b>blind) | (?P<p>paralysed) ) \.\n )+ (?!(deaf|blind|paralysed)).*\z"
multi_line="y"
regexp="y"
send_to="2"
sequence="100"
>
<send>%%0 = %0
deaf = %<d>
blind = %<b>
paralysed = %<p>
</send>
</trigger>
</triggers>
What this does is match:
You are: (followed by)
deaf.
blind.
paralysed. (in any order, and optional)
Followed by a line that does *not* start with
deaf or blind or paralysed.
|
- 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.
12,952 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top