0 votes

Hi! I'm making a dialogue box where I want text to appear slowly over time. I already managed to achieve this effect by using the following code on a Label:

func _physics_process(_delta):
    if visible_characters < get_total_character_count():
        visible_characters += 1

This works, but I also wanted the text animation to pause whenever it met a punctation mark. To do this, I attached an autostart oneshot Timer node to the Label and replaced the old code with this:

func _on_Timer_timeout():
    visible_characters += 1
    if text[visible_characters] in [".", ","]:
        $Timer.start(0.5)
        print('gotcha!') # test
    else:
        $Timer.start(0.05)

    if visible_characters == get_total_character_count():
        $Timer.queue_free()

My issue is that the if statement seems to "lag behind"... It only detects the punctuation a few letters after the actual punctuation mark. What's the issue here? Am I missing something?

Godot version 3.5.1
in Engine by (20 points)

For anyone coming to this question later, changing the type of the Label to a RichTextLabel also seems to do the trick, since spaces are counted as characters in a RichTextLabel!

1 Answer

0 votes
Best answer

Hmmm...

It seems that the visible_characters property of the Label control ignores space characters. Here's some info:

https://github.com/godotengine/godot/issues/34775

Not sure why that's the case. One way to handle it would be to count the spaces as they occur and modify your offsets accordingly. Something like:

var space_count = 0
func _on_Timer_timeout():
    visible_characters += 1
    if text[visible_characters] == ' ': space_count += 1
    if text[visible_characters + space_count - 1] in [".", ","]:
        $Timer.start(0.5)
        print('gotcha!') # test
    else:
        $Timer.start(0.05)
by (19,274 points)
selected by

That is odd! Hope that gets fixed at some point. This suggestion seems to work, so thanks for the explanation!

On the surface, it seems odd to me, but... Thinking about it, I'd guess spaces are ignored to ensure a rhythmic cadence to the exposure of the next visible character. If spaces were considered, and "exposed" just like any visible character, it'd break the visual cadence because there would be a "delay" in the visuals when a space was "exposed"...

Not sure if that's really why, but it seems plausible. That said, it'd be nice to turn that feature on/off via a property.

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 Frequently asked questions and 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 [email protected] with your username.