Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Flipp3rix |
Hi guys, i’m currently having a problem with yield. I do have a function “foo” in a main node script that for every node in a list instantiate a custom node and shows a dialogbox (made by me)
Main script:
var ut: utility = utility.new()
const dialogPrefab= preload("res://Prefabs/UI/DialogBox.tscn")
foo(list: Array):
var position= []
for e in list:
ut.instatiateE(position, e, dialogPrefab, $DialogContainer, $EntityContainer)
That’s the utility class script:
extends Node
class_name utility
func instantiateEnemies(position, e, dialog, parentD, parentE):
var i = randi() % position.size()
e.translation = Vector3(position[i].x,position[i].y, position[i].z)
parentE.add_child(e)
var dia = dialog.instance()
dia.init(e.name + " added!")
dia.set_name("DialogBox")
diaCont.add_child(dia)
yield(dia, "okay")
dia.queue_free()
And that’s my DialogBox script:
extends Control
onready var textPlayer: AnimationPlayer = $NinePatchRect/MarginContainer/Label/TextAnim
signal okay
var text = ""
export var g = false
func init(txt):
text = txt
$NinePatchRect/MarginContainer/Label.text = text
func _ready():
textPlayer.play("DisplayText")
func input():
g = true
$NinePatchRect/ColorRect/AnimationPlayer.play("Blink")
func _process(_delta):
if Input.is_action_just_released("debug") and g:
emit_signal("okay")
g =false
In theory the “for loop” in the main function is interrupted for every enitity in the list until I press(and released) my “debug” action. Now the problem is that in practice it keeps spawning DialogBoxes until the for loop end without waiting my input… How can i handle this situation?