I'm having trouble sanitizing bbcode text for a RichTextLabel
node. I looked at this Reddit post, but it doesn't seem to work. I've tried pasting the character or using a \u200b
in my escape function, and I think that the post was for Godot 2.0 which I have never used. This is my code:
#In singleton called Util
func bbcode_escape(text:String):
var out = text
out.replace("[", "[\u200b")
out.replace("]", "\u200b]")
return out
# In my test:
var print_cache = []
func _ready():
println(Util.bbcode_escape("[color=red]RED[/color]"))
func println(text:String, color:Color=Color.white):
var formatText = printc(text, color, false)
$out.bbcode_text += formatText
func printc(text:String, color:Color=Color.white, doCache:bool=true):
if !text:
return ""
var formatText = "\n[color=#"
formatText += color.to_html(false)
formatText += "]"
formatText += text
formatText += "[/color]"
if doCache:
print_cache.append(formatText)
return formatText
I've tried bbcode_text +=
and .append_bbcode()
. I'm not sure what's wrong.