How to wait for player input or dialog to finish?

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

Hello. Attempting to make a simple first game and I’m working on a scene that picks out random animations and then plays them with dialog (using dialogic) between each animation. However, it seems like the first animations/dialog is being skipped and only the first one is being played. Here is a simple example of the my code. I have taken it out of a for loop.

extends Node2D

onready var animation = $walk_choices/AnimationPlayer

var choices = ["walk1", "walk2"]

func _ready():
	randomize()
	var random = RandomNumberGenerator.new()
	random.randomize()

	var dialog_1 = Dialogic.start("/normal_encounter")
	var dialog_2 = Dialogic.start("/normal_encounter")

	var animation_choice_1 = get_random_animations()
	var animation_choice_2 = get_random_animations()
	
	animation.play(animation_choice_1)
	add_child(dialog_1)
	dialog_1.connect("timeline_end", self, 'after_dialog')
	
    #Add something here to wait until first dialog is finished?

	animation.play(animation_choice_2)
	add_child(dialog_2)
	dialog_2.connect("timeline_end", self, 'after_dialog')

func get_random_animations():

	var choice_int = randi()%2+0
	var random_selection = choices[choice_int]
	return random_selection
:bust_in_silhouette: Reply From: arknvi909

So after hours of reading about what signals, and yield mean I have done it…

animation.play(animation_choice_1)
add_child(dialog_1)
dialog_1.connect("timeline_end", self, 'after_dialog')
yield(dialog_1, 'timeline_end')

You can simply wait for the timeline_end signal to be emitted.
Hopefully this will help someone else.

1 Like

Hey, made an account just to share this. your solution didnt seem to work for me. im currently on 4.2.2 stable. although i did end up finding a solution luckily that is what your doing essentially but tweaked a bit. just thought i would share this for anyone else whos needing a bit of a workaround

func _on_interactable_interacted():
Dialogic.timeline_ended.connect(_on_timeline_ended)
	Dialogic.start("yourtimeline")

func _on_timeline_ended():
	Dialogic.timeline_ended.disconnect(_on_timeline_ended)
	print("dialogic timeline ended")

in my use case i made it hook up to a interactable object but it can be put essentailly into any function.

Hope this helps anyone!

I like my code small and contained, so here is another version using await(works in 4.4.1):

# Dialogue started
await Dialogic.timeline_ended
# Dialogue ended