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.