0 votes

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*

Godot version 3.5.1
in Engine by (12 points)

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

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

Also, these references:

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

$Timer.start() and $Timer.wait_time

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 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 .

1 Answer

0 votes

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)
by (246 points)
edited by

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

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

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.