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.
 Entire forum ➜ MUSHclient ➜ General ➜ Multi Capture With One Trigger

Multi Capture With One Trigger

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


Posted by Gaznox   (6 posts)  Bio
Date Sat 02 Jun 2007 08:21 AM (UTC)

Amended on Sat 02 Jun 2007 08:35 AM (UTC) by Gaznox

Message
Hey, I am trying to figure out how I can use one trigger in order to capture all of the exits and store them in a variable with that exits name. Right now I have:
\b(north|south|east|west|northwest|northeast|southwest|southeast)\b
as the trigger and:
Send("%1","1")
as the script, however when triggered it only captures the first exit. I am curious if I can convert it to somehow pick up the other randomly positioned either/or exits.

The general trigger text looks like this:
You see exits leading north, northeast (open door), east, southeast (open door),
south (open door), southwest, west, and northwest.

You don't know which have open doors and how many exits there will be. Any help would be appreciated.
Top

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #1 on Sat 02 Jun 2007 10:34 AM (UTC)

Amended on Sat 02 Jun 2007 10:35 AM (UTC) by Onoitsu2

Message
You will also need the 'Repeat On Same Line' option checked, so that it will match against the entire line, and not just the first matching part.

And as for the 'Send To Script' part that COULD be accomplished in LUA with...

SetVariable("%1",1)

also as for capturing the doors that trigger COULD be re-designed to something as follows,

(north|south|east|west|northwest|northeast|southeast|southwest)(?:\s\(open (.*?)\))?

Then you could do a check on the "%2" (cause the ?: makes it not capture that outer section) to see if it is not equal to an empty string "", and if not you can do...

SetVariable("%1",1)
SetVariable("%1_door","%2")

Or something along those lines, so that you can store the actual name of the door you have to open, cause it was unclear if you would see door, gate, or other names in place of door, so I prepared for the worst.

Laterzzz,
Onoitsu2
Top

Posted by Gaznox   (6 posts)  Bio
Date Reply #2 on Sat 02 Jun 2007 11:01 AM (UTC)
Message
For some very odd reason it will only capture the first appearance of a match. On the line:
You see exits leading north, northeast (open door), east, southeast (open door),
south (open door), southwest, west, northwest, and in (open door).
It will only return north from the first line and south from the second.

My exact trigger is as follows and I just don't understand why it doest work:

<triggers>
<trigger
enabled="y"
group="Exits"
match="\b(north|south|east|west|northwest|northeast|southeast|southwest)\b"
name="Exits"
regexp="y"
repeat="y"
send_to="12"
sequence="100"
>
<send>SetVariable("%1",1)</send>
</trigger>
</triggers>
Top

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #3 on Sat 02 Jun 2007 02:15 PM (UTC)
Message
I don't think it's possible to do it with a plain trigger, though someone might correct me. To pull out the exits I had to re-parse the string of exits, captured by the trigger, in a script. Like this:


<triggers>
  <trigger
   enabled="y"
   group="Exits"
   match="^You see (?:a single )?exits? leading (.+)$"
   name="Exits"
   regexp="y"
   repeat="y"
   send_to="12"
   sequence="100"
  >
  <send>re = re or rex.new([[(northeast|southeast|northwest|southwest|south|east|west|north|in|out|up|down)(?:,|\.| \((?:open|closed) (door)\))]])
n = re:gmatch("%1", function(m, t) 
  print ("Exit " .. t[1])
  if t[2] then print ("door") end   
end)
</send>
  </trigger>
</triggers>


This should correctly match on all exits, and identify those with doors: need to check the second captured wildcard inside the re:gmatch callback function, as above. If this wildcard is false then there's no door on that exit, if it's true then the exit has a door.
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #4 on Sat 02 Jun 2007 09:40 PM (UTC)
Message
The "repeat on the same line" option is only intended to be used to colour the same word if it appears more than once, not to call a script repeatedly.

Trigger handling is described here:

http://www.gammon.com.au/forum/?id=6554


I have recently amended that post to make this point clear.

In any case, I don't think you would want your trigger to work the way you have written it (eg. matching "north|south|east|west" etc.) because it would fire if someone said something like this:


Gaznox says, where is the Temple?
Nick says, it is north of here


Ooops! Trigger fired.

As Ked said, you really want something like "You see exits leading *", and then inside the trigger script, break down the list of exits. This is very easy in Lua, because you can run a string.gsub to re-parse for individual words.

- Nick Gammon

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

Posted by Gaznox   (6 posts)  Bio
Date Reply #5 on Sat 02 Jun 2007 10:47 PM (UTC)

Amended on Sat 02 Jun 2007 10:48 PM (UTC) by Gaznox

Message
I forgot to add that I am using color matching and the exit trigger is the only line that shows up in blue.

I am using Ked's trigger and it works very well if all of the exits appear on one line. My problem was that there was a line break which would stop the trigger. All I needed to do though was add (.) at the end of the line before the $ and call an if statement to see whether the line officially ended or not.

Trigger:
^You see (?:a single )?exits? leading (.+)(.)$

Added to the script:
if ("%2" == ".") then
print ("end of exits")
else
EnableTrigger("Exits2", true)
end

And then made a replica trigger that is:
^(.+)$

Now it can pick up all the exits in every situation. Thanks for the all of the help.
Top

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #6 on Sun 03 Jun 2007 06:42 AM (UTC)
Message
An easier way to solve the newline problem is to set SCREENWIDTH 0. I forgot to add that my trigger was meant to be used with that.
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.


23,704 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.