Help with color trigger

Post Reply
Puckster
Posts: 24
Joined: Fri Jul 30, 2021 11:51 pm

Help with color trigger

Post by Puckster »

I found some discussion on this topic on old posts, but I did not find a solution.

I want to trigger on the color of a whole line (or even just the first few chars).

The following trigger fires if ANY of the characters in the line are are the trigger color.
Color trigger.PNG
Color trigger.PNG (16.09 KiB) Viewed 441 times
Any thoughts?

User avatar
demonnic
Posts: 767
Joined: Sat Dec 05, 2009 3:19 pm

Re: Help with color trigger

Post by demonnic »

Try something like this
Code: [show] | [select all] lua
-- checks the first five characters to see if they're yellow
-- if you want to check the whole line, change 5 to #line ie "for i=1,#line do"
local isYellow = true
for i=1,5 do
  selectSection(i-1,i)
  if not isAnsiFgColor(11) then 
    isYellow = false 
    break
  end
end
deselect()
if isYellow then
  echo("It's yellow!\n")
end

Puckster
Posts: 24
Joined: Fri Jul 30, 2021 11:51 pm

Re: Help with color trigger

Post by Puckster »

Hmm... not getting it to work. What should I put for the trigger to execute that code? I tried regex .*, but that didn't work.

User avatar
demonnic
Posts: 767
Joined: Sat Dec 05, 2009 3:19 pm

Re: Help with color trigger

Post by demonnic »

Still a color trigger for the color yellow, all the code is doing is checking the first few characters of the line to make sure those are in yellow in particular. And are you getting an error or something?

User avatar
demonnic
Posts: 767
Joined: Sat Dec 05, 2009 3:19 pm

Re: Help with color trigger

Post by demonnic »

ahhh, use 7 rather than 11

Puckster
Posts: 24
Joined: Fri Jul 30, 2021 11:51 pm

Re: Help with color trigger

Post by Puckster »

Aha! Thank you! That explains it.

That last response prompted me to look here https://wiki.mudlet.org/w/Manual:UI_Functions, where I found this:

Code: Select all

0 = default text color
1 = light black
2 = dark black
3 = light red
4 = dark red
5 = light green
6 = dark green
7 = light yellow
8 = dark yellow
9 = light blue
10 = dark blue
11 = light magenta
12 = dark magenta
13 = light cyan
14 = dark cyan
15 = light white
16 = dark white
Very helpful! Especially since the number are differnt that in the coloro trigger:
ANSI Colors.PNG
ANSI Colors.PNG (9.46 KiB) Viewed 412 times

User avatar
demonnic
Posts: 767
Joined: Sat Dec 05, 2009 3:19 pm

Re: Help with color trigger

Post by demonnic »

Yeah, I'm not sure why those numbers don't match up, but that's what caught me out.

Puckster
Posts: 24
Joined: Fri Jul 30, 2021 11:51 pm

Re: Help with color trigger

Post by Puckster »

Me too. Now we know! :-)

User avatar
SlySven
Posts: 1001
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Help with color trigger

Post by SlySven »

Very helpful! Especially since the number are differnt that in the coloro trigger:
The colour selection dialogues for the colour triggers are referring to the ANSI 256-colour indexes (which are what the MUD Game Server will be sending) - but the list you are quoting came from a long standing function tempColorTrigger(...) which had that choice of numbers baked in back in the mists of time. Unfortunately they are NOT ANSI codes - so to get around that I added tempAnsiColorTrigger(...) which does use those numbers {as well as a couple of special case ones with negative values...!}

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

Re: Help with color trigger

Post by Vadi »

Updated the docs so we find the alternative easier =)

Post Reply