Random beginner-question: animate a single character within a label

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

Hi everyone,

I wonder how I could have a single character in a text within a label to be animated under one certain circumstance.

I have a RichTextLabel connected to some number- and a comma-button. Only one comma is possible, so entering one makes the comma-button “inactive”… it still registers tapping though, so in my func _on_Button_button_comma_pressed_while_disabled(): I can apply all kinds of “there’s-already-a-comma-written!”-reactions (like e. g. a rapidly blinking cursor).

Now I’d like the comma itself in the text to blink a couple of times when that function is triggered. Could I somehow find(‘,’) or get(“,”) and then maybe apply some Tween-animation or even bbcode? Or is there an easier way I just can’t think of?

:bust_in_silhouette: Reply From: astrale

Hey there, yes you could! let me elaborate!

lets assume you have some code like:

onready var my_rich_text_label = $Rich_Text_Label

then in your function you could have

_on_Button_button_comma_pressed_while_disabled():
        text = my_rich_text_label.bbcode_text
        text.replace(",","[custom_bbcode_tag],[/custom_bbcode_tag]")
        #maybe then wait a little bit and replace back the comma so the animation stops

you’ll have to implement your custom bbcode tag, i suggest reading the documentation on that subject

:bust_in_silhouette: Reply From: Andrea

i dont think there is any built in function to do it, but you can create your own system using replace(text, ",", " ") to create the blink effect (replace , with an empty space), linked to a timer that will repeat this action a couple of time

:bust_in_silhouette: Reply From: pferft

Hi Andrea and astrale,

thanks for your suggestions, I’m sure this is exactly what I’m looking for. The visible mentioned in the docs will be what I’m aiming at.

I already have several bbcode working in my RichTextLabel, including var templateAlwaysAllRight = "[right][color=blue]{alwaysAllRight}[/color][/right]" for some alignment. Now, when I’m adding e. g. text.replace(",","[color=green],[/color]"), entering 1,2 and then tapping the disabled , again, it leads to [right][color=blue]1,2[/color][/right] being displayd as text in my RichTextLabel…

This is about as far as my beginner-understanding goes at this point, so I wonder (and guess): two “separate” bbcodes can’t apply to the same object? So would I need to have them both combined in one? Or am I missing something else?

EDIT:
The docs describe in Custom BBCode tags (e. g.)

var bbcode = "ghost"

func _process_custom_fx(char_fx):
...

that can then be used as [ghost] ... [/ghost], but I don’t see how ghost is connected to the function (so how ghost would “know” its own variables). So I wonder how I can make [ghost],[/ghost] work (as [custom_bbcode_tag] in your example)?