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

Gammon Software Solutions 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?
(New message)
Subject: Capturing same thing more than once in a single line.
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Sat 27 Nov 2004 02:30 AM (UTC)  quote  ]

Amended on Sat 27 Nov 2004 02:31 AM (UTC) by Nick Gammon

Message
In the example above, I had a simple trigger that matched the word "will" (regular expression), omitted from output (so you didn't get two of them), and called the script shown above.

Notice how the colour of the original line is retained.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Sat 27 Nov 2004 02:28 AM (UTC)  quote  ]
Message

Hell
As if picked up by the scruff of your neck by a mighty hand, you find
yourself unceremoniously dumped at a strange gateway.  Here is the
place which *WILL* determine your fate.  Whether you *WILL* be sent back
to life as you once knew it, or proceed onto a far yet bleaker pathway.
The time has come for you to plead your case and await judgement for the
crimes that have been placed upon your head.  Speak wisely and choose
your words carefully, for your testimony *WILL* be written in the ledgers
of the Gods, and *WILL* determine the path you *WILL* ultimately travel.
Exits: none.
A mystical spring flows majestically from a glowing circle of blue.
A fountain of fresh blood flows in the corner.
A demon imp hovers nearby...drooling constantly with a fiendish grin.

<1000hp 100m 110mv> 
think I will go to sleep
You think 'I *WILL* go to sleep'

<1000hp 100m 110mv> 
<1000hp 100m 110mv> 

- Nick Gammon

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

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Sat 27 Nov 2004 02:28 AM (UTC)  quote  ]

Amended on Sat 27 Nov 2004 02:42 AM (UTC) by Nick Gammon

Message
Well, I think I have worked out a way of solving the "replace stuff in lines" problem. The major problem so far has been that in trigger matching, if you try to do fancy omitting from output in "send to script" any world.notes are also omitted, and if you wait until a trigger script (in the script file) executes, the original line has already been omitted.

I was reluctant to alter the way trigger calls worked, because that would break existing scripts. However with Lua, there is a way *grin*.

Lua allows optional arguments, so I have added a fourth argument to the trigger script (only available under Lua). This fourth argument is a table of all the style runs in the matching line, including the text colour, background colour, text itself, and the style type (eg. bold).

Now with a simple bit of scripting, you can replace one word with another. Here is an example:


function my_trigger (name, line, wildcards, styles)

  for _, v in pairs (styles) do
    
    ColourNote (RGBColourToName (v.textcolour), 
                RGBColourToName (v.backcolour), 
                (string.gsub (v.text, "will", "*WILL*")))  
  end

end



I think this is pretty self-explanatory. It echoes the existing line to the output window with ColourNote (translating colour numbers to colour names). This keeps existing colours. Then by doing a gsub (global substitution) it replaces the word "will" by "*WILL*".

Now of course, if "will" spans a colour boundary, then it won't match, but that sort of problem is the thing that was always going to be a problem with trying to replace words in coloured text. The next post will show how it looks:

- Nick Gammon

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

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Fri 26 Nov 2004 11:05 PM (UTC)  quote  ]
Message
Yes, the problem already exists, but what you are asking is for something to be retrospectively changed on the screen. At present all the "problem" is, is that trigger don't fire until a newline.


- Nick Gammon

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

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Fri 26 Nov 2004 10:23 PM (UTC)  quote  ]
Message
Which is why I dont see it at a major problem. Yes, its going to sometimes be an awkward transition, for slow connections or prompts, or a few other situations. But we do the same with omitting.
Yes, it doesnt work quite like we'd like it to, but we cant control the servers, and it isnt a crippling problem.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Fri 26 Nov 2004 09:51 PM (UTC)  quote  ]
Message
So the problem exists already, it's not exclusive to the replacement function.

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

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Fri 26 Nov 2004 08:29 PM (UTC)  quote  ]
Message
Yes, when the newline eventually appears, *after* they have entered their name.

- Nick Gammon

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

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Fri 26 Nov 2004 08:02 PM (UTC)  quote  ]
Message
Quote:

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.

What happens if the user wants to omit "Enter your name*" from output? Doesn't this still happen?

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

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Fri 26 Nov 2004 06:06 AM (UTC)  quote  ]
Message
The replace thing wasnt in any seriousness, I know the design problems (especially considering it wouldnt get to Lua until after it matched, which means after it was displayed, which well, yeah, weve been over this).

As for color, I'd just as soon have it be ANSI sequences. And MXP, and everything.
If someone is going to be screwing around with low level stuff, they should be able to take care of colors/MXP/whatever.
Just like in assembly, or C, or whatever, as opposed to something higher (VBscript), yes, you MIGHT have overflows, or whatever, but since youre coding at a lower level, thats to be expected, and youre expected to be able to take care of that.

As for the line triggering problem, its the same thing if youre omitting. Yes, you might be inserting something, or changing something, but we do the same thing with things being omitted.

And make it a plugin callback, I think that would be the most useful. Because you'd shield 'normal' users from it, and wouldnt have to rewrite anything that already exists. Just give the plugin the line, and have it return the new line (both including color/mxp/etc, just an assembly of packets, let the plugin writer deal with everything, to give him the most flexibility).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Thu 25 Nov 2004 11:55 PM (UTC)  quote  ]
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

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Thu 25 Nov 2004 09:17 PM (UTC)  quote  ]
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 Somegirl   (33 posts)  [Biography] bio
Date Thu 25 Nov 2004 08:19 PM (UTC)  quote  ]
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 Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Thu 25 Nov 2004 08:02 PM (UTC)  quote  ]
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 Flannel   USA  (1,230 posts)  [Biography] bio
Date Thu 25 Nov 2004 07:24 PM (UTC)  quote  ]
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 Somegirl   (33 posts)  [Biography] bio
Date Thu 25 Nov 2004 07:21 PM (UTC)  quote  ]
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

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.


6,739 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]