Thread Tools Display Modes
02-06-24, 02:45 AM   #1
atshn
A Deviate Faerie Dragon
Join Date: Feb 2024
Posts: 19
Changing the color of print(message)?

Is it possible to change the color of the message printed? I'd prefer yellow over the default white.

Code:
local function OnEvent(self, event, errorType, message, lineID)
	if errorType == 298 then
		print(message)C_Timer.After(5,function()SELECTED_CHAT_FRAME:Clear()end)
	end
end
  Reply With Quote
02-06-24, 06:17 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
I googled around and this familiar note turned up. Not sure if it still works, but theoretically it shouldn't have needed to be changed with their api changes.

print("\124cffFF0000This text is red\124r") --This is red color

Prefix = "\124"
== HexColor RRGGBB
== Your text
Suffix = "\124r"
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
02-06-24, 09:01 AM   #3
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
To clarify a little more:

Prefix is "|c" for text color. However, if you're typing, input boxes filter out UI escape sequences. Using "\124c" instead bypasses that, but not required if the print call is in an addon file. 124 is the ASCII number for the vertical bar.

Then, the color code is eight hex digits (0 to 255, so 00 to FF) in the ARGB format (alpha, red, green, and blue). Alpha is not actually utilized as far as I know, haven't tested it in years, so the first two digits are always FF for 100%.

Next is the text that will be colored, followed by an optional suffix of "|r" for "reset". It's not required, but if you want text further in the line or box to be the default color for that font object, you need to reset the color sequence. It's good practice to always include the reset suffix to prevent unintended effects where the color bleeds over if anything queries or views the contents of the font string, such as addons that mirror chat for copying or in Lua errors that include the font string.

To include this color change for the print call shown:

print("|cffffff00"..message.."|r")

More information on UI escape sequences can be found here:
https://warcraft.wiki.gg/wiki/UI_escape_sequences

Last edited by Kanegasi : 02-06-24 at 09:08 AM.
  Reply With Quote
02-06-24, 03:25 PM   #4
atshn
A Deviate Faerie Dragon
Join Date: Feb 2024
Posts: 19
Originally Posted by Kanegasi View Post
To clarify a little more:

Prefix is "|c" for text color. However, if you're typing, input boxes filter out UI escape sequences. Using "\124c" instead bypasses that, but not required if the print call is in an addon file. 124 is the ASCII number for the vertical bar.

Then, the color code is eight hex digits (0 to 255, so 00 to FF) in the ARGB format (alpha, red, green, and blue). Alpha is not actually utilized as far as I know, haven't tested it in years, so the first two digits are always FF for 100%.

Next is the text that will be colored, followed by an optional suffix of "|r" for "reset". It's not required, but if you want text further in the line or box to be the default color for that font object, you need to reset the color sequence. It's good practice to always include the reset suffix to prevent unintended effects where the color bleeds over if anything queries or views the contents of the font string, such as addons that mirror chat for copying or in Lua errors that include the font string.

To include this color change for the print call shown:

print("|cffffff00"..message.."|r")

More information on UI escape sequences can be found here:
https://warcraft.wiki.gg/wiki/UI_escape_sequences
That worked perfectly. Thanks for the in-depth response. Much appreciated!
  Reply With Quote
02-06-24, 03:36 PM   #5
atshn
A Deviate Faerie Dragon
Join Date: Feb 2024
Posts: 19
Originally Posted by Xrystal View Post
I googled around and this familiar note turned up. Not sure if it still works, but theoretically it shouldn't have needed to be changed with their api changes.

print("\124cffFF0000This text is red\124r") --This is red color

Prefix = "\124"
== HexColor RRGGBB
== Your text
Suffix = "\124r"
My knowledge is very limited, so hopefully I'm using the right terminology. Doesn't seem to work for printing the arg, but it does works fine if the message is in quotations. Kanegasi's response above did the trick.
  Reply With Quote
02-06-24, 05:31 PM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Ah yes, the |c was more familiar rofl.

Glad you got it all sorted though
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Changing the color of print(message)?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off