(c#) how to use richtext tags through setting richtext label through code?

Godot Version

4.1

Question

How would I use richtext tags to set a richtextlabel through code? (I am trying to make a dialogue system and the tag won’t set properly, so I am not able to color text, make it shake, etc.)

You can use the dedicated push_* methods, see the documentation for details

here is something to gnaw on.

public override void _Ready() {
	RichTextLabel v_label_1 = new RichTextLabel();
	v_label_1.Size = new Vector2(200,100);
	v_label_1.BbcodeEnabled = true;
	v_label_1.Text ="Hello normal, [b]bold[/b], [i]italics[/i]";
	AddChild(v_label_1);

	RichTextLabel v_label_2 = new RichTextLabel();
	v_label_2.Position = new Vector2(100,100);
	v_label_2.Size = new Vector2(200, 100);

	v_label_2.PushBoldItalics();
	v_label_2.AddText("PushBoldItalics");
	v_label_2.Pop();

	v_label_2.PushBgcolor(Colors.Red);
	v_label_2.AddText("red bg color");
	v_label_2.Pop();

	AddChild(v_label_2);
}

oh I didn’t realize I had to enable bbcode, doing that in the editor fixed it.

2 Likes