RichTextLabel and [color]

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DimitriyPS
:warning: Old Version Published before Godot 3 was released.

I have in the global script there is a variable of type Color. I need to use this color in the tag RichTextLabel [color]. How do I convert to the format of the tag [color]?

BBCode expects a color name: BBCode in RichTextLabel — Godot Engine (latest) documentation in English

So you’d have to make an equivalence table to convert RGB to the nearest color name.

Akien | 2016-09-15 12:49

:bust_in_silhouette: Reply From: Chr_

[color=aqua]Check this [/color]

No, wait, that’s not it.

I’m telling you, the color that I want to use is stored in a variable of type: “Color”:

var c_MyColor=Color(r,g,b,a)

The tag RichTextLabel [color] doesn’t accept this variable… or am I doing it wrong?

DimitriyPS | 2016-07-28 14:24

You would have to use parse_bbcode I believe and use +str(colorvariable) dynamically when updating the text I believe

wombatTurkey | 2016-07-28 14:44

No it is not working:

var c_MyColor=Color(r,g,b,a)

RichTextLabel.set_ddcode("[color="+str(c_MyColor)+"] Bla bla bla... [/color]")

is not working… Please tell me how to really possible do it?

DimitriyPS | 2016-08-22 15:12

Just replace Color(r,g,b,a) with “#hexcodevalue

wombatTurkey | 2016-08-22 18:45

My game is very advanced interface. That’s a lot of complex scenes. Colors which are stored in variables (in global scripts) are used for different purposes. If I decide to change some color, I prefer to change one variable. So I don’t want to use the “#hexcodevalue” locally.

Prompt how to convert a Color variable in the “#hexcodevalue”?

DimitriyPS | 2016-08-23 06:47

:bust_in_silhouette: Reply From: vnen

I think you can use something like this:

var rich_label = get_node("RichTextLabel")
rich_label.push_color(my_color)
rich_label.append_bbcode("Colored text")
rich_label.pop()

If you really need a text, you can convert Color to HTML notation:

rich_label.set_bbcode("[color=#"+my_color.to_html(false)+"]Colored text[/color]")

rich_label.set_bbcode("[color=#"+my_color.to_html(false)+"]Colored text[/color]")

This is - I could not find. It works, thank you very much.

DimitriyPS | 2016-09-15 17:58