WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Changing the color of print(message)? (https://www.wowinterface.com/forums/showthread.php?t=59784)

atshn 02-06-24 02:45 AM

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


Xrystal 02-06-24 06:17 AM

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"

Kanegasi 02-06-24 09:01 AM

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

atshn 02-06-24 03:25 PM

Quote:

Originally Posted by Kanegasi (Post 343286)
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!

atshn 02-06-24 03:36 PM

Quote:

Originally Posted by Xrystal (Post 343285)
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.

Xrystal 02-06-24 05:31 PM

Ah yes, the |c was more familiar rofl.

Glad you got it all sorted though :)


All times are GMT -6. The time now is 03:30 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI