text speed in dictionary

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

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

:bust_in_silhouette: Reply From: Eric Ellingson

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

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?

Sakura37 | 2019-11-16 13:01