+1 vote

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]?

in Engine by (355 points)

BBCode expects a color name: http://docs.godotengine.org/en/latest/reference/bbcode_in_richtextlabel.html#built-in-color-names

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

2 Answers

+3 votes
Best answer

I think you can use something like this:

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

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]")
by (801 points)
selected by

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.

0 votes

[color=aqua]Check this [/color]

by (83 points)

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?

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

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?

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

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"?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.