Skip to content

Instantly share code, notes, and snippets.

@erdavids
Last active July 10, 2023 20:13
Show Gist options
  • Save erdavids/db39bd67dc420ed41ad385334154bc25 to your computer and use it in GitHub Desktop.
Save erdavids/db39bd67dc420ed41ad385334154bc25 to your computer and use it in GitHub Desktop.
extends Node2D
var messages = [
"My First Message",
"Second Message For You"
]
var typing_speed = .1
var read_time = 2
var current_message = 0
var display = ""
var current_char = 0
func _ready():
start_dialogue()
func start_dialogue():
current_message = 0
display = ""
current_char = 0
$next_char.set_wait_time(typing_speed)
$next_char.start()
func stop_dialogue():
# get_parent().remove_child(self)
queue_free()
func _on_next_char_timeout():
if (current_char < len(messages[current_message])):
var next_char = messages[current_message][current_char]
display += next_char
$Label.text = display
current_char += 1
else:
$next_char.stop()
$next_message.one_shot = true
$next_message.set_wait_time(read_time)
$next_message.start()
func _on_next_message_timeout():
if (current_message == len(messages) - 1):
stop_dialogue()
else:
current_message += 1
display = ""
current_char = 0
$next_char.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment