How do I change the color of text in a Label from Lua?

General Tso

Panzer General
Joined
Oct 12, 2007
Messages
1,548
Location
U. S. of A.
All I want to do is change the color of text in a UI Label from Lua. I just want to change the RGB (plus alpha) values and I can't find any way to do it. The SetColorByName function appears to be limited to the colors already defined to the game and the SetColorVal function uses some kind of perverted x,y,z system which I don't understand and have no interest in understanding. Isn't there a simple way to change the freaking color of text?
 
Controls.myLabel:SetText(string.format("[COLOR:%d:%d:%d:%d]%s[ENDCOLOR]", r, g, b, a, text))

where r, g, b and a are ints in the range 0 - 255 and text is the string you wish to display
 
You can use text = Controls.myLabel:GetText() if you don't know what's in the label
 
OK thanks. It's probably obvious from my first post but I was getting kind of frustrated with this. Out of desperation I finally just used two separate Labels at the same location with one being hidden and the other not, then toggling them as needed. Your method is definitely superior so I'll switch things.
 
Back
Top Bottom