Changing the color of a RichTextLabel based on conditions

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By retsi3602

Hey im trying to make a game where based on user input the game gives them a result of perfected, good or incorrect.

In this function I’m trying to change the color of the text based on what is in the text but i really don’t know what I’m doing.

extends RichTextLabel

export (Color,RGB) var text_color

func _ready():
set_modulate(text_color)
pass

func _text_color_changer():
if “Perfected” in text:
text_color = Color(0,255,0)
elif “Good” in text:
text_color = Color(100,200,0)
elif “Incorrect” in text:
text_color = Color(200,0,0)
pass

func _on_LineEdit_text_entered(new_text):
_text_color_changer()

Also if you can i would also like to know how to make the text fade out couple seconds after it appears?

Thanks guys.

:bust_in_silhouette: Reply From: LoneDespair

You could directly apply it to your text via modulate or self_modulate = Color(0, 0, 0)

As for the animation you could use Animation Player
and key its modulate if you used self_modulate and vice versa

and adjust the line for time a little further by milliseconds and then
set a another key with lower opacity

and then call it in your code $AnimationPlayerPAth.play(“Anim Name”)