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 ➜ Coloring certain words

Coloring certain words

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


Posted by Penguin   (46 posts)  Bio
Date Wed 14 Aug 2002 02:20 PM (UTC)
Message
Currently if I wish to perhaps trigger "A duck floats by" and color "duck" in custom color 1 and "floats" in custom color 2, I will set two triggers with regular expressions, one: (duck) and the other: (floats)

However this will not only color the duck and floats in the line, but also color any duck and floats which appears in the game. Is there an easier way to perhaps choose which words to color ( and in what color) in a certain string?
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #1 on Wed 14 Aug 2002 08:19 PM (UTC)
Message
In your Mushclient directory (or one of it's subs), there is a file called "RegularExpressions.txt". Read that for very useful help on the subject.

Off the top of my head, you might be able to use a regular expression like this:

(?:A )(duck)(?: floats by)


In a related topic, I would like to eventually figure out how to replace a string with another string, using a trigger. For example, I would like to write a routine that:

Triggers on any number 5 digits or larger,
Inserts comma's into the number,
Replace the old string with the new string.

Nick has mentioned that it is (or will be), possible to grab input/output before it is processed by any aliases or triggers. I wonder if it would be possible to grab in incoming line, replace some or all of it, then submit it back to the client for outputting to the screen, which could then be triggered upon by the standard triggers.

One imporatant note, I would like to retain the formatting for the line/string.

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Guest1   USA  (256 posts)
Date Reply #2 on Wed 14 Aug 2002 09:00 PM (UTC)
Message
funny you should mention that example Magnum, I had someone ask me the exact same thing yesterday about inserting commas into 4+ digit numbers. I didn't have an answer for them at the time. :)
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 15 Aug 2002 10:37 PM (UTC)
Message
If you tried you could probably make a routine (that could be "included") that takes an existing line (including colouring) and turns it into a "note" line, preserving colours, by using GetLineInfo and GetStyleInfo.

However such a line would be a bit of a simulation, eg. it would be marked internally as a "note" line and not an "output" line (which might affect "recall") and also would discard MXP formatting (eg. hyperlinks).

I suppose it could be changed to allow "line preprocessing" where a line from the MUD could be submitted for text changes (eg. adding commas in numbers) and then sent on for ANSI code recognition, MXP codes and so on.

However I would be a bit worried about the speed of such a thing, it would mean that every input line would go through (say) VBscript which would probably slow it down quite a bit.

Maybe an external DLL could supply such preprocessing, or, perhaps, a variation of a trigger. Still, could be fiddly. For example, say we got a word like this coming in:

"Swordfish" (but with colouring), so it really arrives as:

Sw<font color=red>ordfi</font><font color=green>sh</font>

Now say you wanted a trigger to match on "Swordfish" and change it to "Tuna". Just running that line through regexp processing (trigger processing) would result in no match, because of the MXP codes (or ANSI colour codes would have the same effect).

Even suppose that you could make a match, then what happens to the colouring when you change "Swordfish" to "Tuna" - where do the red and green letters start?

I understand what you are trying to achieve, but think that for a general case there would be so many if's and but's that it wouldn't be a great result.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #4 on Thu 15 Aug 2002 10:42 PM (UTC)
Message
Quote:

Currently if I wish to perhaps trigger "A duck floats by" and color "duck" in custom color 1 and "floats" in custom color 2, I will set two triggers with regular expressions, one: (duck) and the other: (floats)


I can't think of a really easy solution, but this might work:

1. Set up a trigger that matches a line *other* than the one you are matching on - Magnum is the expert on lines that don't match, he might be able to comment. This will effectively "catch" the non-matching lines (don't set "keep evaluating"). ie. Match all lines except "A duck floats by".

2. Set up two more triggers "duck" and "floats" with a higher sequence number (eg. 110) and have them colour those words.

That way, if the line gets past trigger 1, it will be coloured by triggers 2 and 3.

- Nick Gammon

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

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #5 on Fri 16 Aug 2002 02:41 AM (UTC)
Message
Nick... Uh... Too complicated, as you have stated. I don't actually need the line to be processed after I modify it yet, so... sooner or later I'll tackle this project and just use the World.Note.

I'll forget about crossing bridges of speculation, and wait till I really need to cross that bridge before trying to figure it out.

Regarding Penguin's original post, I think my original suggestion may work.

The ?: indicates that although the trigger should look for the expression within those brackets, it should not return that expression as part of any wildcard.

Thus, the word in the circle brackets by itself should be the only expression returned, and coloured. The other expressions ensure that the word you want is triggered only in the context you want. Uhm does that make sense? :)

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #6 on Fri 16 Aug 2002 03:18 AM (UTC)
Message
Yes it makes sense, and is simpler than my solution, so I thought you were absolutely brilliant, except for one small problem - it doesn't work. :)

When MUSHclient colours the matching part of a trigger, it colours the entire matching text (%0). Unfortunately your solution of:

(?:A )(duck)(?: floats by)

restricts the %1 to "duck" however %0 is still "A duck floats by" and that is what gets coloured. Try it and see.

I have got my solution to work, after a lot of trial-and-error. The key seems to be to make the "negative" regexp to have a wildcard in addition to what you *don't* want to match on. Here is what works for me, it colours "duck" and "floats" in the sentence "You think 'A duck floats by'" but not at other times. I added the "you think" bit because I was testing it by typing "think A duck floats by".


<triggers>
  <trigger
   enabled="y"
   match="^(?!You think \'A duck floats by\')(.*?)$"
   regexp="y"
   sequence="110"
  >
  </trigger>
  <trigger
   custom_colour="2"
   enabled="y"
   keep_evaluating="y"
   match="duck"
   regexp="y"
   sequence="120"
  >
  </trigger>
  <trigger
   custom_colour="7"
   enabled="y"
   keep_evaluating="y"
   match="floats"
   regexp="y"
   sequence="120"
  >
  </trigger>
</triggers>

- Nick Gammon

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

Posted by Penguin   (46 posts)  Bio
Date Reply #7 on Fri 16 Aug 2002 05:25 AM (UTC)
Message
Well perhaps I'm being too irritating here, but maybe another way MUSHclient could be improved and be more user friendly is maybe to change the interface for coloring triggers? Perhaps highlight certain parts of a trigger which you wish to highlight in different colors and then you will be able to choose which colors you want?

I know it seems like a bit retarded since its already possible to make this work, but when everything is possible, won't it better to make things easier?
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #8 on Fri 16 Aug 2002 07:13 AM (UTC)
Message
Heh Heh Heh.... Well, this settles it, I absolutely picked the correct tagline for my postings here. :)

Ah well, live and learn.

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Guest1   USA  (256 posts)
Date Reply #9 on Sat 17 Aug 2002 07:17 AM (UTC)
Message
hmm.. would it take much to make this possible Nick?;

If you made a trigger "A duck floats by" (that has omit from output selected) which triggers a subroutine that world notes "A duck floats by" and you were able to set colors within the world.note message by typing it something like

world.note "\c1A \c2duck \c1floats by"

where the \c# just changes the color of text following it, and \c1 = white, \c2 = red etc (for example), then this would work fine.
If there was no \c# in the world.note text, it would just default to your settings as it does in current client versions.

just a thought.
Top

Posted by Shadowfyr   USA  (1,788 posts)  Bio
Date Reply #10 on Sat 17 Aug 2002 07:09 PM (UTC)
Message
Try:

world.colourtell "white","black","A "
world.colourtell "red","black","duck "
world.colournote "white","black","floats by"

;)
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #11 on Sun 26 Dec 2004 04:28 AM (UTC)
Message
Quote:

In a related topic, I would like to eventually figure out how to replace a string with another string, using a trigger. For example, I would like to write a routine that:

Triggers on any number 5 digits or larger,
Inserts comma's into the number,
Replace the old string with the new string.


You can now do that with a plugin which does OnPluginPacketReceived and modifies the incoming text.

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


30,508 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.