This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello! I managed to get a dialogue system for my game using a Dictionary, but i don't know how to set the speed for the text(like a typewriter)

    textbox_name.clear()
textbox_dialogue.clear()
textbox_name.add_text(event_queue[event_queue.size() - 1]["name"])
textbox_dialogue.add_text(event_queue[event_queue.size() - 1]["text"])
event_queue.pop_back()

How can i set the speed?Thank you in advance

in Engine by (92 points)

1 Answer

0 votes
Best answer

Does something like this work?

signal output_finished

# Called when the node enters the scene tree for the first time.
func _ready():
    textbox_name.clear()
    textbox_dialogue.clear()
    textbox_name.add_text(event_queue[event_queue.size() - 1]["name"])
    var text = event_queue[event_queue.size() - 1]["text"]
    show_text(text)
    yield(self, "output_finished")

    event_queue.pop_back()

func show_text(text: String, rate: float = 0.1):
    textbox_dialogue.visible_characters = 0
    textbox_dialogue.text = text

    while textbox_dialogue.visible_characters < len(text):
        textbox_dialogue.visible_characters += 1
        yield(get_tree().create_timer(rate), "timeout")

    emit_signal("output_finished")

I put your code in the _ready() method just because I don't know where else you have it, but you can put it wherever obviously

by (1,663 points)
selected by

Yes it works! you just need to swap the yield line with the event queue line.
I am triggering my next line using the space key. I want the first pressing of my space key to write all the text instead of typewriting it, and the second pressing of the space key to write the next line. i tried working with some variables, in the while and input function, but i could't make it happen. Do you have any ideas?

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.