[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Capturing same thing more than once in a single line.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Capturing same thing more than once in a single line.

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


Pages: 1 2  

Posted by Somegirl   (33 posts)  [Biography] bio
Date Wed 24 Nov 2004 04:39 PM (UTC)
Message
Here's what the output looks like:

Blah, Blah, Blah, Blah, Blah, Blah,

The end of the line can contain the last "Blah" in the following ways:
Blah
Blah,
Blah, <--one space

I want to capture and send to a list each "Blah" which are names that are always capitalized. I've tried triggering several combinations with ([A-Z][a-z]+) in it to match and capture the names. But then when I do world.Note "%1" to test and see if it gets them all, it doesn't seem to.

Currently I'm making do with a trigger that captures everything and a subroutine that split()'s it. I have had other instances where I would like to capture multiple items of the same type on a single line. So not only would I like to stop using a .* trigger and make it cleaner, but I've had other instances where I can't figure out how to do something like this.

I think this is also similar to colouring individual words in a line, which I would also like to be able to do.

Any ideas? Sorry if I'm missing something obvious here.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #1 on Wed 24 Nov 2004 09:21 PM (UTC)
Message
You can color individual words, just use a regexp, and match just that word.

You should be able to catch the names, want to post some examples?

However, if the same trigger matches multiple times on a line, then it will only get sent to script once (You can have that trigger match, and then get the whole line and split it up though).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Somegirl   (33 posts)  [Biography] bio
Date Reply #2 on Thu 25 Nov 2004 09:36 AM (UTC)

Amended on Thu 25 Nov 2004 09:43 AM (UTC) by Somegirl

Message
Yeah, that's what I do already. I send the whole line to script and split it up there. I was just hoping for something cleaner that could do it in the trigger itself. I'm not sure if I'm making myself clear here.

I get a block of names between prompts like I posted. It's multiple lines with several names in each line. A line can end with a comma, a comma and a single space, or nothing (i.e. just the name). I want to capture all the names in each line individually and append them to a list in Python.

As for coloring individual names, I can't figure out how to do that without coloring the whole line. I've looked through the forums, but the solutions presented seemed to indicate that I needed to replace the entire line with one that colors the one word or name. So I am probably missing something simple.

btw: I never use anything but a RegExp if I can help it.

Edit: okay I figured out how to do one-word coloring. Now my question becomes:
How do I color multiple different items in the same line like the the QWHO list in IRE games. Do I need to make a trigger for each name? Can I (hopefully) squeeze them all into a single trigger? I haven't tried yet as I was in a hurry to edit. I will come back after I look into it.
[Go to top] top

Posted by Gore   (207 posts)  [Biography] bio
Date Reply #3 on Thu 25 Nov 2004 09:53 AM (UTC)
Message
Quote:
<triggers>
  <trigger
   custom_colour="17"
   enabled="y"
   expand_variables="y"
   group="colors"
   ignore_case="y"
   keep_evaluating="y"
   match="(@!friends)"
   regexp="y"
   sequence="100"
   other_text_colour="royalblue"
   other_back_colour="white"
  >
  </trigger>
</triggers>


<variables>
  <variable name="friends">somegirl|gore|nick|flannel|shadowfyr|</variable>
</variables>


etc, this'll color those names when they are seen in the qw list or anywhere

(note, I didn't write this script! there was a post about this before)

Is this what you needed?
[Go to top] top

Posted by Gore   (207 posts)  [Biography] bio
Date Reply #4 on Thu 25 Nov 2004 09:55 AM (UTC)
Message
sorry, I didn't come up with the idea of these "triggers" not script heh, also you can modify it so that you have an alias like, fr person, to add name| to your variable, or remove, or ally/unally, or whatever etc etc
[Go to top] top

Posted by Gore   (207 posts)  [Biography] bio
Date Reply #5 on Thu 25 Nov 2004 09:59 AM (UTC)
Message
Hrm, actually I just tested this.. and it won't color say, Nick if Nick is on the same line twice. Any ideas?
[Go to top] top

Posted by Gore   (207 posts)  [Biography] bio
Date Reply #6 on Thu 25 Nov 2004 10:01 AM (UTC)
Message
Ok sorry, I answer'd my own question, heh. The trigger should be as follows:

Quote:
<triggers>
  <trigger
   custom_colour="17"
   enabled="y"
   expand_variables="y"
   group="colors"
   ignore_case="y"
   keep_evaluating="y"
   match="(@!friends)"
   regexp="y"
   repeat="y"
   sequence="100"
   other_text_colour="royalblue"
   other_back_colour="white"
  >
  </trigger>
</triggers>


Note, repeat on same line has been checked, where it wasn't before.
[Go to top] top

Posted by Somegirl   (33 posts)  [Biography] bio
Date Reply #7 on Thu 25 Nov 2004 10:03 AM (UTC)
Message
Yup, 'repeat on same line' makes it work. Now why won't it work to capture like I intend?
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Thu 25 Nov 2004 06:20 PM (UTC)
Message
Trigger scripts are only executed once per line, not once per match.

However there are ways of processing the capture multiple times.

For a start, under Lua you have a "gmatch" function that applies a regular expression to a string, and then calls a function that you supply for every match. Here is an example:


t = rex.new ("(a|b|c)")

function f (m, t)
  Note ("Matched: " .. m)
end -- function

t:gmatch ("cat mat bat catch", f)

-- output:

Matched: c
Matched: a
Matched: a
Matched: b
Matched: a
Matched: c
Matched: a
Matched: c


So, what you can do in your trigger script (given that it is only called once) is get the regular expression, and then apply it to the matching line as shown above.

Remember, to get the trigger match string (what it matches on), just do this:

s = GetTriggerInfo ("triggername", 1)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Somegirl   (33 posts)  [Biography] bio
Date Reply #9 on Thu 25 Nov 2004 07:21 PM (UTC)
Message
Huh?

Nooo! Don't make me learn another language!
You're really hot on this Lua thing aren't you? Maybe I can find something in Python eventually. But right now, I'll just script it like I have been by delineating. Thanks anyhow. That answers my question.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #10 on Thu 25 Nov 2004 07:24 PM (UTC)
Message
Basically He's just splitting.

You only get the script called once per line, not once per match (if it matches multiple times on a line), so you have to work around that.

And yeah, he seems to have discovered Lua, and gone crazy.
Although, it does solve many things that we couldnt do before (callbacks, and better usage of other windows).

Nick, any chance Lua might be able to insert things on lines, so we dont have to omit/note? Or clean my room?

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Thu 25 Nov 2004 08:02 PM (UTC)
Message
Quote:

I'll just script it like I have been by delineating


With any language you can take the entire line and reprocess it to find the submatches. My example in Lua just showed the idea.

Quote:

And yeah, he seems to have discovered Lua, and gone crazy.


Indeed. ;)

Quote:

Nick, any chance Lua might be able to insert things on lines, so we dont have to omit/note?


You still have the fundamental design problems with doing that - things like that fact that lines arrive in pieces (packets) not necessarily terminated by a newline. When do you start matching? At the end of a packet? Say you want to replace "kobold" with "monster" and you get:

packet 1: kobo
packet 2: ld

When does the "find and replace" get triggered off? And what of ANSI codes? MXP codes? MXP entities?

Quote:

Or clean my room


How dirty is it?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Somegirl   (33 posts)  [Biography] bio
Date Reply #12 on Thu 25 Nov 2004 08:19 PM (UTC)
Message
Wouldn't
(.*?)
and checking the omit from log/output take care of stuff in your room? Of course, it might have adverse effects on things you don't want omitted. (girlfriends, pets, etc...)
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #13 on Thu 25 Nov 2004 09:17 PM (UTC)
Message
Quote:

When does the "find and replace" get triggered off? And what of ANSI codes? MXP codes? MXP entities?

Well, it would get triggered off the newline, since you don't really need to match it as it comes, only when it's done, and about colour codes, it's a compromise, as it's better than nothing, for example:
Say I want to replace "blue bear" with "red horse"
<green>You see a <blue>blue<green> bear.
The output would be
<green>You see a <blue>red horse.

Ideally, we would be able to add raw ANSI codes to the string to be replaced, but still, not many lines I want to replace have more than one color.
About the color thing, think you could change it to match on raw colors? Like, add an option, which for example would have triggers of this style:
<green>*gets damaged! <blue>It scraps!

Essentially triggers would not omit the colour codes, but would instead keep them as normal text we could match on, so we could do:
\1B[31m*some red text.
Would match on "\1B[31mSome red text".

Wouldn't that be as easy to implement as just keeping the colour codes in the line and adding an option? It would allow us to match colors that change mid-line, although, as I said, those are not very frequent.

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #14 on Thu 25 Nov 2004 11:55 PM (UTC)
Message
OK, say you have at least two packets to make up a line, not something that is particularly unusual.

Now when the first one arrives, MUSHclient has to display it, in case there is no second packet.

eg.


Welcome to Blah MUD!
Enter your name ...


Now if I wait for the newline, you don't get to see "Enter your name ...". If I don't then the text is already on the screen, it is a bit late to start doing find-and-replace on it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


13,777 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]