Page 1 of 3

Marking in colour one word

Posted: 04 Oct 2015 21:00
by kirsach
Hi
Do any of you knows how to mark in colour based on t pattern one word only and not a whole line?

Re: Marking in colour one word

Posted: 07 Oct 2015 14:18
by britanica
You can change the colour of a text phrase by using a <span> element with a color style attribute

* Click on settings
* Click on Triggers Tab
* Click on Add new trigger
* Click the Regexp button for Trigger Type
* Enter Pattern: You find a (.*)[\.|!]
* Click Javascript for the Script Type
* Enter the below code

Code: Select all

gwc.output.replace(args[0], 'Found: <span style="color: rgb(0,255,0)">' + args[1] + '</span>', true);
gwc.output.color('#888888');
* Click Save
* Close settings popup
* Go herbing

In the above code, args[0] is the full text of the line that matches the regexp pattern. args[1] is captured text from (.*) that was found between "You find a " and either a "!' or a "."

Re: Marking in colour one word

Posted: 09 Oct 2015 17:06
by kirsach
Many, Many thank Britanica Your example is very useful. But puting my question I was thinking about somethin else. I wanted to mark one word only.
Lets imagine I love to collect diamonds. . After w day of killing I have 100 of gems. But to quick see how many of diamonds I have I would like to mark them in colour. The same apply to quick check if a mob wield or wear looked equipment. Do you know how to do it?

Re: Marking in colour one word

Posted: 10 Oct 2015 01:18
by britanica
To change the colour of individual words you can use the following

Trigger Pattern: (.*)

Code: Select all

var hilites = ['diamond', 'wielding', 'wearing'];
hilites.forEach( function(word) {
    gwc.output.replace(word, '<span style="color: rgb(255,255,0)">' + word + '</span>', true);
});
This will result in the output looking like


The deadly slight male elf has the look of wisdom in his eyes, a wisdom which is only learned through age. Faint wrinkles line his face. Nonetheless, he still appears agile enough.
He is wearing a decorated purple robe and a plain silver tunic.
He has pointed ears.
He is wielding an exceptional shiny shortsword in his right hand.
He is nodding solemnly.
He is extremely tall and very skinny for an elf.
He looks like the image of perfection.
He seems to be feeling very well.


If this is not what you had in mind, can you provide a sample of the output you are trying to achieve?

Re: Marking in colour one word

Posted: 29 Oct 2015 14:50
by Alisa
I love your explanations, with scripts :-)

I understand how to work the app and triggers now ! (somewhat)


Just one question, that makes me wonder...

Another example had a trigger like :
Trigger: ^There (are|is) (.*) obvious (exits|exit): (.*)[\.]

Would it not be safer, to use the trigger :(diamond|wielding|wearing)

I just forgot to tick javascript after the regex triggger (.*), which gives an eternal loop in the app, as it spams in resonse to what :-) That trigger seems dangerous to me.
I don´t know how it works, but i would image it would slow the entire thing down too, with checking everything.

Re: Marking in colour one word

Posted: 30 Oct 2015 09:47
by britanica
Alisa wrote:
Would it not be safer, to use the trigger :(diamond|wielding|wearing)
...
I don´t know how it works, but i would image it would slow the entire thing down too, with checking everything.
You are correct on both counts. Specifically looking for individual words is safer and faster

I did update my trigger to use a similar version a few hours after posting as the client seamed to be hanging a little. I also had a larger list of words to hilite and each line is checked for each word meaning multiple passes on each line received.

It also means you can get rid of the array of names and changes the body of the trigger to:

Code: Select all

gwc.output.replace(args[1], '<span style="color: rgb(255,255,0)">' + args[1] + '</span>', true);

Re: Marking in colour one word

Posted: 30 Oct 2015 09:48
by britanica
------------

Re: Marking in colour one word

Posted: 30 Oct 2015 10:06
by Alisa
Cool :-)

Love understanding stuff!

Thanks.

Re: Marking in colour one word

Posted: 21 Nov 2015 02:46
by kirsach
Britanica

Your tips were super up today. Last Cotillion's modification with "Automatically disable triggers found to be looping" has broke down this trig. The trig looked like:

Code: Select all

Type: regexp
Pattern: (.*)

code:
var hilites = ['wielding', 'wearing'];
hilites.forEach( function(word) {
    gwc.output.replace(word, '<span style="color: rgb(127,255,0)">' + word + '</span>', true);
});
Unfortunately the last modification/improvement introduced yesterday disable this trig after some time(10-20 min), even if I dont exa anyone. I'm not sure if this any looping system works as planned but we will need to find another solution to mark one word with color.

Re: Marking in colour one word

Posted: 21 Nov 2015 12:16
by Alisa
the (.*) trigger hits every line, so i guess it gets detected as a loop.(triggering on every output from mud)

If you do the pattern as

(wielding|wearing)

and the command as

gwc.output.replace(args[1], '<span style="color: rgb(255,255,0)">' + args[1] + '</span>', true);

It should be good :-)