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 ➜ Just wondering about a replace/substitute feature

Just wondering about a replace/substitute feature

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


Posted by Jesusonacid   (1 post)  Bio
Date Fri 27 Feb 2004 06:02 AM (UTC)
Message
Just wondering if any new versions will have a feature to replace certain strings on the muds. A novelty feature really use to make things on the mud appear differently. I think it would be kool to see it in the client.
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #1 on Fri 27 Feb 2004 03:06 PM (UTC)
Message
Hm true, could the wildcards be passed to the script by reference so we could do:
strWildcards(1) = "New string"
?

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #2 on Fri 27 Feb 2004 08:43 PM (UTC)
Message
It would have to be a callback, wouldnt it? allow you to change things before they were evaluated by triggers, etc?
Otherwise we'd have the possibilities for some nasty loops.

Havent we discussed this before? or am I making that up.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 27 Feb 2004 09:03 PM (UTC)
Message
It has been discussed, and is tricky to do.

The problem is that, while it sounds simple to replace (say "bob" with "bob the killer robot") that is only easy in a simple single-colour line.

However if there are colours involved the incoming text actually looks something like this (assuming ESC is the "escape" character hex 1B)...

You see ESC[31mbESC[32moESC[33mb here.

That is saying "You see bob here" where the letters in "bob" are each in a different colour.

Now a simple "replace bob with something else" won't find a match, and then you will complain that the "text replace" feature doesn't work.

But say we strip out the colours first, then the text replace will work but what colour is the replacement text? After all, we started with 3 letters, all in different colours, and you are replacing with 20 letters. Where do the colours change?

A similar problem happens with MXP processing. Say you have MXP codes that make a hyperlink, and the text replacement crosses the hyperlink boundary. Where does the hyperlink end now, that the text has changed?

My suggestion is, that you *can* do it right now, if you have a MUD where colour is not a big feature. You can make a trigger that matches something, and do a "note" (send to output window) to replace the word with something else.

Here is an example of doing that:


<triggers>
  <trigger
   enabled="y"
   match="*bob*"
   omit_from_output="y"
   send_to="2"
   sequence="100"
  >
  <send>%1bob the killer robot%2</send>
  </trigger>
</triggers>


What that does is put a wildcard on each side of "bob" and then send %1 (whatever came before the word "bob") followed by the new text "bob the killer robot" and then %2 (whatever came after the word "bob").

However what this does is strip out any colours that may have been on that line and replace them with the "world note" colour. You can change that colour to the normal text colour so it isn't too obtrusive.

- Nick Gammon

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

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #4 on Fri 27 Feb 2004 10:07 PM (UTC)
Message
Couldnt we use the new ANSI functionality to help with that?

if it were bob with color codes, then thatd be fine, itd just be like a regexp with a space somewhere, we'd just have to be even more nitpicky with our triggers. And the ANSI sequences could be used to replace colors as well.
There are still some issues, but those can be worked out Im sure.

Nick, I think most of us have arrived at a consensus that the note workaround isnt adequate for most peoples usage.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #5 on Sat 28 Feb 2004 12:56 AM (UTC)
Message
OK, I suppose what could be done is a simple text replacement on incoming packets.

Now that would be your problem if there are imbedded colour codes, you would have to put them in the "find" string. Ditto for MXP sequences.

You would have to accept that colour code sequences can be broken across packets, eg.

packet 1: you see ESC[3
packet 2: 1m bob here

That would fail if the "packet by packet" test was for ESC[31m.

Also you might get this:

packet 1: you see bo
packet 2: b here

In this case the test for "bob" would fail.

However I suppose it could be done, but I won't accept responsibility if it screws up text in the "borderline" cases I describe above.

In practice, such a thing may well work 99% of the time, which may be acceptable.

What do you think?

- Nick Gammon

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

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #6 on Sat 28 Feb 2004 01:22 AM (UTC)
Message
I personally believe folks are asking more of the client than it should ever be expected to do and will probably still be unhappy with the performance of such a feature if it is implemented. The overhead on such an implementation would be nigh rediculous on most mu*s if the examination of every single packet is required. People have already reported performance issues with the partial line feature that was recently implemented and I can only imagine a replace feature being more performance intensive.

Not saying the feature can't be done, but I think we all need to step back and look at the big picture for a minute before trying to pressure Nick into coding something most of us arent going to want when he's done with it.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #7 on Sat 28 Feb 2004 01:45 AM (UTC)
Message
Personally.. I think it would make more sense to limit replacement to *only* those things that are the same color. That way it will work in 90% of the cases anyone wants to use it, by just shifting everything in the final string to fit the replaced text. In cases where more than one color is found in the sequence, it should either ignore all but the first color or fail. Not the best solution, but for most people it would work.

Packet based processing is shaky at best and short of give the user the entire like 'with all codes' and letting the script modify it and return the changed result back to the client, it isn't very practical.

My own choice would be some way to have Mushclient process a line to be output, even if it contained MXP or ANSI code. This line should 'never' be run through triggers, it merely displays, so you could have a trigger option that could be used with 'omit from output' that did something like 'return wildcard(0) with codes'. In other words, you script would get the entire line, complete with any MXP that effects the contents of the line and let the user find and replace whatever they need to, then feed that changed line into a World.NoteInbeded command or something, that would process the line for output, but not to the triggers.

Frankly, I wouldn't mind seeing both. Some way to do quick and dirty replacements when that works, but also the option to tweak things more directly when it can't work. For most users though, the script intensive option would be more complex than they want. If you go the packet path, then by definition you end up with a script only solution, which imho isn't very friendly...
Top

Posted by Gore   (207 posts)  Bio
Date Reply #8 on Mon 01 Mar 2004 05:20 PM (UTC)
Message
What I usually do is gag the line, (omit from output) then call a sub to colournote a replacement line. For instance:

Quote:
<triggers>
  <trigger
   enabled="y"
   group="stances"
   keep_evaluating="y"
   match="^You allow the form of the Dragon to fill your mind and govern your actions\.$"
   omit_from_output="y"
   regexp="y"
   script="stance_dragon"
   sequence="100"
  >
  </trigger>
</triggers>

Dim stance
Sub Stance_Dragon (a,b,wildcard)
  stance = "drs"
  World.ColourNote "black", "white", "Dragon stance."
End Sub


Does anyone know if it's faster to make a sub just for two lines of code, or would it better to just have the trigger script it out in the trigger (send to script)?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #9 on Mon 01 Mar 2004 07:50 PM (UTC)
Message
Didn't I get asked that last week?

A separate script file is faster as it is compiled once.

"Send to script" has to get parsed (compiled) every time. However two lines is probably not a big deal.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #10 on Sat 11 Dec 2004 10:08 PM (UTC)
Message
Version 3.59 allows you to use a plugin to simply replace one thing with another at the incoming packet level. Bearing in mind problems with text split between packets, and colour codes inside lines, if the thing you want to change always appears in a single packet, and never has colour codes in it, then it is very easy to do in this version onwards.

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


36,927 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.