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?