bbcode format is being displayed as text in richtextlabel

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

Hi everyone,

I have two templates set up in a RichTextLabel:

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

var templateGap = "[right][offset x=-10 y=0]{firstDigit}[/offset]{remainingDigits}[/right]"

In a function then accordingly:

bbcode_text = templateAlwaysAllRight.format({ "alwaysAllRight" : text })

bbcode_text = templateGap.format({ "firstDigit": text[0]}, {"remainingDigits": text.substr(1)})

The first one works wonderfully. But the second one (supposed to separate the first digit a bit from the rest) doesn’t, instead it actually displays “[offset x=-10 y=0]{firstDigit}[/offset]{remainingDigits}” directly in the label. It does right-align though!

Any idea what I am missing here?

:bust_in_silhouette: Reply From: aipie

I believe it’s with your parameter in the second one.
In your example you are providing 2 parameters (dictionaries) instead of one dictionary with two elements.

Try this:

bbcode_text = templateGap.format({ "firstDigit": text[0], "remainingDigits": text.substr(1)})

Although I’m positive that you are right, unfortunately this still doesn’t solve the issue. For whatever reason the format-text still appears in the label. Any other hint is much appreciated.

pferft | 2022-03-28 21:43

Ok, I checked this out in Godot itself this time and got it working.

offset does not exist as a bbcode tag, but can be implemented as a custom tag.

I followed the code from this post

You can see a code file for “RichTextOffset” in that post.

Afterwards on your richtextlabel you have to add this extra tag.
In the inspector find the “custom effects” and add the Richtextoffset.

That should do it.

aipie | 2022-03-29 17:59

It’s rather funny that you linked my own post from over a year ago, isn’t it? So technically I should have been able to make things work, but for whatever reason this time I wasn’t, so there must be something else going on. I’ll find out, thanks for your help!

pferft | 2022-03-31 13:34