Is there a way to control text speed via BBCode?

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

I have an animated label node, and I want to be able to set its speed via BBCode for more dynamic dialog (that is, so that text speed could be changed mid-sentence). I know it’s possible to have custom BBCode tags, but I can’t for the life of me figure out how it’s supposed to be written.

The thing is, BBCode applies to static text, while the animation is controlled by the label itself. Thus, the only solution I can think of is emitting a signal that would contain the speed parameter. But then, what exactly would emit the signal? What should the label expect the signal from?

If a custom BBCode tag is the way, is there a way to have this tag look simply like [speed=0.5], like the color tag for instance? Every custom BBCode tag I’ve seen has some extra parameters after the tag name (which in my case would lead to something like [speed new_speed=0.5], which seems redundant).

I’m not sure the custom BBCode system is designed to allow something like that. It will actually depend on how you make that text progressively appear in the first place. I would probably make a custom system for this which pre-parses such special BBCodes and then appends bits of text at the desired speed manually, or sets “visible characters” to specific counts known in advance with the pre-parsing, so that you know which speed the “current character index” is at. If you can get the character index ranges for each speed, it shouldn’t be too difficult, but either way it means you’ll have to use a script instead of an animation (or an animation that controls a script).
There is also RichTextEffect I’m not familiar with, but maybe something in it can help (or not).
Sorry if that means more work than hacking with built-in features, but I’m not aware of something built-in for doing this^^"

Zylann | 2023-07-04 12:48

It’s not really an animation, I just called it that cuz I called the class AnimatedRichLabel. (Should I choose a different name?)

My line printing code is actually as simple as adding +1 visible character on a timer:

func print_line():
	visible_characters = 0
	for i in get_total_character_count():
		visible_characters += 1
		await get_tree().create_timer(time_between_letters / text_speed).timeout

RichTextEffect is exactly the thing I was talking about, but once again, it doesn’t (normally) affect the speed, only the text itself. But as I’ve learned recently, signals can be emitted by literally anything in Godot, so I might actually try using a signal to change the speed.

MysticalKitsune | 2023-07-04 15:55