Marking in colour one word

General discussion about the Genesis Web Client located at https://www.genesismud.org/play/

Moderator: Eowul

Forum rules
- Use common sense and be respectful towards each other at all times, even when disagreeing.
- Do not reveal sensitive game information. Guild secrets, player seconds are examples of things not allowed.
User avatar
kirsach
Wanderer
Posts: 67
Joined: 23 Sep 2014 20:33

Marking in colour one word

Post by kirsach » 04 Oct 2015 21:00

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

User avatar
britanica
Wizard
Posts: 45
Joined: 28 Sep 2015 16:42

Re: Marking in colour one word

Post by britanica » 07 Oct 2015 14:18

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

User avatar
kirsach
Wanderer
Posts: 67
Joined: 23 Sep 2014 20:33

Re: Marking in colour one word

Post by kirsach » 09 Oct 2015 17:06

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?

User avatar
britanica
Wizard
Posts: 45
Joined: 28 Sep 2015 16:42

Re: Marking in colour one word

Post by britanica » 10 Oct 2015 01:18

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?

User avatar
Alisa
Hero
Posts: 392
Joined: 16 Nov 2014 23:10

Re: Marking in colour one word

Post by Alisa » 29 Oct 2015 14:50

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.

User avatar
britanica
Wizard
Posts: 45
Joined: 28 Sep 2015 16:42

Re: Marking in colour one word

Post by britanica » 30 Oct 2015 09:47

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);
Last edited by britanica on 30 Oct 2015 10:02, edited 2 times in total.

User avatar
britanica
Wizard
Posts: 45
Joined: 28 Sep 2015 16:42

Re: Marking in colour one word

Post by britanica » 30 Oct 2015 09:48

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

User avatar
Alisa
Hero
Posts: 392
Joined: 16 Nov 2014 23:10

Re: Marking in colour one word

Post by Alisa » 30 Oct 2015 10:06

Cool :-)

Love understanding stuff!

Thanks.

User avatar
kirsach
Wanderer
Posts: 67
Joined: 23 Sep 2014 20:33

Re: Marking in colour one word

Post by kirsach » 21 Nov 2015 02:46

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.

User avatar
Alisa
Hero
Posts: 392
Joined: 16 Nov 2014 23:10

Re: Marking in colour one word

Post by Alisa » 21 Nov 2015 12:16

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

Post Reply
http://tworzymyatmosfere.pl/przescieradla-jedwabne-z-gumka/