Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Melvin |
I am trying to setup a dialog system where some words and hints are colored to emphasize them, like so:
I’ve noticed that Godot has BBCode for the RichTextLabel node, but I’ve not figured out how to integrate it with the system I’ve set up. For the purpose of this question, I’ll provide the most basic code of what I’m working with:
extends RichTextLabel
var NPC_TEST = []
func SET_NPC_TEST():
NPC_TEST.push_back("<NPC NAME>")
NPC_TEST.push_back("Hello! I am a NPC, and this is the color RED.")
pass
var TIMER = Timer.new()
var WAIT_TIME = 0.05
var LINE = 0
var LINE_ARRAY = []
func _ready():
TIMER_START()
READY_NPC()
START_DIALOG()
pass
func READY_NPC():
SET_NPC_TEST()
pass
func TIMER_START():
TIMER.connect("timeout", self, "TIMER_TIMEOUT_FUNCTION")
TIMER.set_wait_time(WAIT_TIME)
add_child(TIMER)
TIMER.start()
pass
func TIMER_TIMEOUT_FUNCTION():
if LINE_ARRAY.size() > 0:
self.add_text(LINE_ARRAY.pop_front())
pass
pass
func START_DIALOG():
if LINE < NPC_TEST.size():
LINE += 1
LINE_ARRAY = []
for i in NPC_TEST[LINE]:
LINE_ARRAY.append(i)
pass
pass
pass
Note: I know “pass” does not do anything, it is just a habit of mine.
Anyway I hope my setup isn’t too complicated, but lets take a gander at this line:
NPC_TEST.push_back("Hello! I am a NPC, and this is the color RED.")
I would like the word “RED” to be… well, red.
I know this doesn’t work:
NPC_TEST.push_back("Hello! I am a NPC, and this is the color [color=red]RED[/color].")
Any tips and tricks to get around this would be greatly appreciated!