Very Basic Help Needed

Post Reply
Avriel
Posts: 2
Joined: Mon Feb 20, 2012 10:12 pm

Very Basic Help Needed

Post by Avriel »

:oops:
I'm going to have a bunch of these, so I'll ask your forbearance in advance. I'm brand new to coding and sort of floundering here.

I've been trying to do highlights on a line that contains a certain amount of unknown text, but the highlight switch seems to only highlight the (.*) part.

Trigger:
^You have slain (.*).$

where the (.*)could be whitespace and up to 4-5 words, and only that will get highlighted leaving the "You have slain" alone.

I've tried turning that off, and putting in some stuff into the script box that I found in some threads that sounded like it should work, but to no avail.

selectString(line, 1)
fg("red")
resetFormat()

I'm sure the answer is really easy, but I've literally been reading threads and looking in the manual for a half hour and can't for the life of me figure it out. :oops: Eventually I want to make a script for hunting that will use the trigger to make me pick up the corpse when I next get balance, but if I can't even get this to work...

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Very Basic Help Needed

Post by Rakon »

If you want the whole line highlighted with RegEx type then you'll need to use scripting instead of the built-in 'trigger highlight' from Mudlet. Its apparently a 'feature' that only the captured group is highlighted.... :?

Create your trigger, Regular expression type:

Code: Select all

^You have slain (.+?)\.$
In the script, to highlight the whole line use :

Code: Select all

selectString(line,1)
fg('red')
resetFormat()
The highlighting will not work, if obviously the trigger line does not match, or if the trigger is not enabled/not of the Regular Expression type.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Very Basic Help Needed

Post by Vadi »

Yeah, it's a feature - you can still put brackets around the whole thing if you'd like it highlighted.

Otherwise, this great feature is useful for seeing what is your pattern capturing, without any code, and juxtaposed onto the line itself!

Avriel
Posts: 2
Joined: Mon Feb 20, 2012 10:12 pm

Re: Very Basic Help Needed

Post by Avriel »

Tired, so I must be doing something wrong, but that doesn't seem to work for me.
I'll give it another look in the morning.
Thanks for the help and patience so far! :)

User avatar
Gilmo
Posts: 25
Joined: Fri Feb 11, 2011 11:43 am

Re: Very Basic Help Needed

Post by Gilmo »

You can use the standard highlight feature just by matching the whole triggers. Remove the "()" from you trigger.
^You have slain (.*)$
to
^You have slain .*$
Image

This works for me and highlight the whole line.

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Very Basic Help Needed

Post by Rakon »

Gilmo:
That highlights the whole line, but then defeats the purpose of capture groups for RegEx. You'd be better off using a substring match in that case.

Vadi:

showCaptureGroups() isn't exactly a hard line to type to .. well, highlight the individual captures!

User avatar
Gilmo
Posts: 25
Joined: Fri Feb 11, 2011 11:43 am

Re: Very Basic Help Needed

Post by Gilmo »

Rakon wrote:Gilmo:
That highlights the whole line, but then defeats the purpose of capture groups for RegEx. You'd be better off using a substring match in that case.
That will only match the substring you put in.

Post Reply