0 votes

Hi everyone,

I have a RichTextLabel set up including:

export (NodePath) var pre_comma_digits


    var leftandrightofcomma = text.split(",", true, 1)
    get_node(pre_comma_digits).text = leftandrightofcomma[0]

So whenever I put some numbers in, they appear correctly in my PreCommaDigits-RichTextLabel as well. (The post-comma digits appear in another Label...)

With Bb Code I'd like these numbers to be aligned right, so within PreCommaDigits I coded:

extends RichTextLabel

var templateAlwaysAllRight = "[right]{content_to_align}[/right]"

func _ready():

    var the_numbers = self.text 
    bbcode_text = templateAlwaysAllRight.format({ "content_to_align": the_numbers })

I wrote "PRE" in the Bb Code textfield in the editor and this really is right-aligned at start. However, as soon as I enter numbers, they are displayed left aligned.

I tried things like



label.bbcode_text =  "[right]{replaceThis}[/right]"
label.bbcode_text = label.bbcode_text.format({"replaceThis":self.text})

and alike but all to no avail.
I'm not sure why this happens, but I assume I'd somehow need to get the "dynamically entered" numbers into a variable to be put into the right place then.

How could that be done? Any suggestions are much appreciated!

Godot version 3.2.3
in Engine by (381 points)

1 Answer

0 votes

I'm not 100% sure if this is the issue, but

get_node(pre_comma_digits).text = leftandrightofcomma[0]

sets the text of pre_comma_digits and not the bbcode text, so maybe that's the issue?

by (7,336 points)
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.