Coloring single words on a line.

Posted by MushclientNewbie on Tue 30 Mar 2004 05:45 AM — 7 posts, 30,780 views.

USA #0
It's been asked before and I read all I could out of what I found with search. But I am still very confused. What I want to do is color a single word on a line. For instance - someone's name on the who, scan, and where lists. Or - a 'nothing.' slot on my equipment list. Here's a sample equipment list:

<used as light>      (Glowing) a tarnished lantern
<worn on finger>     the ring of life
<worn on finger>     nothing.
<worn around neck>   nothing.
<worn around neck>   nothing.

As you can see, I don't have anything worn on the 2nd ring or either of the neck slots. Matching 'nothing' and coloring it has worked for me with this list, but the who lists matching and whatnot is where the problems come in. Especially when I watch that person in battle and it colors his damage returns. But - that is a bit too hard to describe I think. If any of you could help me re-color just the 'nothing' variable on this eq list I think I could work out what I needed elsewhere.

Oh, all the rest of the equipment slots are the same. < and > around a 'worn on.' I tried matching just those with the period at the end of nothing - but it still colored the whole line :(.
Amended on Tue 30 Mar 2004 05:48 AM by MushclientNewbie
USA #1
Hah, I got it to work. All I did was set the trigger text to:

" * nothing."

Then, selected the 'Regular expression.' box. Now, can anyone explain why that worked?!
USA #2
You got lucky... lol

Seriously, though I really do mean that. * and . have completely different meaning in regular expressions than in normal triggers. Basically by licking 'regular expression', you are now telling it to look for:

<space><one or more of> nothing<any character>

This means that it would not only match what you intended, but something like:

"                                     nothingy"

"  nothing "


It would still capture that single word, but if you had a line like:

"He said:  nothing but net!"

it would still color the word, since there is at least two spaces, matching the " * " part and 'nothing' is followed by more stuff. It would also match:

"  nothingness!"

for the same reason and would color " nothingn" in that line, though you wouldn't notice the spaces it captured in any of these cases, unless you had it color the background as well.

To make it work as intended, and not match a lot of stuff you don't want you need to tell it to look for a real "." and an end of line. Since "." has a special meaning <any character>, you need to tell Mushclient you really do want a period by adding a "\". To tell it to look for the end of a line you use "$", so your trigger, to work properly, should be:

"nothing\.$"

This isn't 100% perfect, since it will match on 'any' line that contains "nothing." at the end, but it is as close as you can hope to get, since anything more precise would color everything on a line, not just the word you wanted.

However.. One trick you can use to get around this is to use two triggers:

"^<\w+ \w+ \w+>\s+nothing\.$"
Color: --what you wanted for the 'nothing' word--
Sequence: 99

"^<\w+ \w+ \w+>\s+"
Color: --what you want it to be normally--
Sequence: 100

"^" means, the following *must* be at the start of a line. "\w+" means it will only look for letters that can appear in a word and it will look for more than one. "+" works the same as "*" in regular expressions and means <find more than one of these>. "\s+" looks for any number of spaces. By setting one triggers "sequence" lower than the second one, you can color the entire line, then the second trigger will match and only recolor the first part of the line, returning it to the color you would normally see. The only issue with this is it means you need to make sure to use 'Other...' when picking colors, since the custom colors need to stay the same as the normal ANSI colors. But the "Other..." option is a lot nicer to work with anyway imho. ;)
Amended on Wed 31 Mar 2004 12:25 AM by Shadowfyr
Australia Forum Administrator #3
The simple answer is, that if you want to colour a single word on a line, make a *regular expression* consisting of simply that word.

eg.
Match: nothing
Regular expression: checked
Colour: whatever

Also check "keep evaluating" if you want to colour multiple words. (eg. "worn on finger" as well).
USA #4
Yeah, I noticed that 'nothing' was getting highlighted in room descriptions and everything else. So, I changed the trigger to match on:

 *> * nothing
Thanks for the regular expression help, though. Works better than the hack-kneed stuff I was doing ^^. I think I'll be able to get the who/where/battle matches worked out with this. Now, if I could just pick a color that didn't give me a headache...
Amended on Wed 31 Mar 2004 07:19 AM by MushclientNewbie
#5
Now... for some strange reason, I can't get this to work at all...

I'm trying to colour bodypart words on triggers like this one:

You will now attempt to parry attacks to your head.

I just want to highlight 'your head'. But either I don't have anything highlighted, or the whole line gets highlighted.

I originally used a '*your head*' because the words could pop up pretty much anywhere in the sentence depending on the attack. It worked pretty good other than the excessive amount of yellow I saw on my screen thanks to full line highlights. >_> But I'd like to clean up my screen a bit.
USA #6
In the other thread, which is talking about this same sort of thing...
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4013&page=999999

this is talked about.

What you do is make your trigger match on 'your head' and check regular expression (the RegExp bit is important, it changes the way triggers match drastically)