How to make my text velocity decrease in the end of the period

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

my actual code is

var textspd

func _on_Timer_timeout():
	get_node(".").visible_characters += 1
	
func _ready():
	$"Timer".start()
	get_node(".").visible_characters = 0
	textspd = 1
func _physics_process(_delta):
	textspd = 1
	get_node("Timer").wait_time = textspd * 0.1
	print("visible characters = ", get_node(".").visible_characters)

how do i get to make textspd increase if the last character is a . or !, ? ?

*get_node(“.”) is a label

Unrelated to your question, but you really don’t need any of those get_node(".") calls. That just references the current node, which will happen by default… So, instead of this (for example):

get_node(".").visibile_characters = 0

you can simply do this:

visible_characters = 0

jgodfrey | 2022-11-30 19:49

i think i couldn’t do this in unity. i’m migrating to godot yk

Digno | 2022-11-30 21:11

Also, these references:

$"Timer".start() and get_node("Timer").wait_time can simply be:

$Timer.start() and $Timer.wait_time

jgodfrey | 2022-11-30 21:27

For the actual question…

how do i get to make textspd increase if the last character is a . or !, ? ?

That’s a little ambiguous. Do you want to change the speed if the current character is one of those listed (so, at the time that char is about to be displayed), or do you want to change the speed for the entire string if the last character in the string is one of those listed?

jgodfrey | 2022-11-30 21:31

jgodfrey said:

That’s a little ambiguous. Do you want to change the speed if the
current character is one of those listed (so, at the time that char is
about to be displayed), or do you want to change the speed for the
entire string if the last character in the string is one of those
listed?

Yes, I was confused about that part as well .

Juxxec | 2022-12-01 08:10

:bust_in_silhouette: Reply From: Juxxec

I would rewrite your code as follows (hope I understood your question correctly):

extends Label


var text_speed := 1.0
var elapsed_time := 0.0


func _ready():
   self.visible_characters = 0


func _physics_process(delta):
   # Waits for text_speed seconds. 
   # 1.0 equals one second, 0.5 equals half a second)
   yield(get_tree().create_timer(self.text_speed), "timeout")

   # Reveal next character
   self.visible_characters += 1

   # This is the check for the punctuation
   if ["!", ".", "?"].has(self.text[self.visible_characters]):
        # This is your pause in punctuation
        yield(get_tree().create_timer(0.5), "timeout")

    print("visible characters = ", self.visible_characters)

How could i check for the ?, ., ! one time each?

if ["!", ".", "?"].has(self.text[self.visible_characters])

this line would check every frame after the first punctuation.

My idea was to decrease the speed of the punctuation so it would do a little pause every time it ended a period. it would make a more natural dialogue box

Digno | 2022-11-30 23:06

Okay, now I understand. Pretty simple, you can still use the yield word, just wait longer. I have updated my answer, check it out. @Digno

Juxxec | 2022-12-01 08:07