Genesis Forums
https://www.genesismud.org/forums/

Marking in colour one word
https://www.genesismud.org/forums/viewtopic.php?f=37&t=3289
Page 1 of 3

Author:  kirsach [ 04 Oct 2015 21:00 ]
Post subject:  Marking in colour one word

Hi
Do any of you knows how to mark in colour based on t pattern one word only and not a whole line?

Author:  britanica [ 07 Oct 2015 14:18 ]
Post subject:  Re: Marking in colour one word

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

Author:  kirsach [ 09 Oct 2015 17:06 ]
Post subject:  Re: Marking in colour one word

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?

Author:  britanica [ 10 Oct 2015 01:18 ]
Post subject:  Re: Marking in colour one word

To change the colour of individual words you can use the following

Trigger Pattern: (.*)

Code:
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?

Author:  Alisa [ 29 Oct 2015 14:50 ]
Post subject:  Re: Marking in colour one word

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.

Author:  britanica [ 30 Oct 2015 09:47 ]
Post subject:  Re: Marking in colour one word

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

Author:  britanica [ 30 Oct 2015 09:48 ]
Post subject:  Re: Marking in colour one word

------------

Author:  Alisa [ 30 Oct 2015 10:06 ]
Post subject:  Re: Marking in colour one word

Cool :-)

Love understanding stuff!

Thanks.

Author:  kirsach [ 21 Nov 2015 02:46 ]
Post subject:  Re: Marking in colour one word

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

Author:  Alisa [ 21 Nov 2015 12:16 ]
Post subject:  Re: Marking in colour one word

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 :-)

Page 1 of 3 All times are UTC + 1 hour [ DST ]
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/