Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | IHate |
I’m using a yield inside of a function like this:
unit.play_turn(action)
yield(unit,"action_finished")
next_unit_in_queue()
But the code after the yield never gets executed even though the signal is being emitted.
I created a function connected to this signal to check and it is called at the right time, but the yield doesn’t break I have used yields in this manner before and never encountered this problem? Does anyone have any ideas of what may be causing this?
You may want to post test code that fails so people can bring it into the IDE. Would be easier for people to spot a problem. E.g. maybe the signal name is wrong. Right now it’s a guessing game.
wyattb | 2021-06-18 12:48
Sorry I fixed it yesterday but I actually didn’t change anything about the signals just cleaned the code around these functions. At the time I created a function connected to this signal and it worked so the name of the signal is right, using print I got this output:
#BattleManager.gd
func create_unit():
var unit :Unit = Unit_scn.instance()
unit.connect("action_finished", self, "action_finished_foo")
func action_finished_foo():
printerr("action_finished signal received")
func turn_preparation(unit):
printerr(" - turn_preparation - ")
unit.play_turn(action)
yield(unit,"action_finished")
print("yield resumed")
next_unit_in_queue()
func next_unit_in_queue():
printerr(" - next_unit_in_queue -")
#Unit.gd
func play_turn(action):
# I commented everything else just to test the signal
emit_signal("action_finished")
The output looked like this:
- turn_preparation -
action_finished signal received
So I knew I didn’t write the signal name wrong and that it was emitted at the right time.
but the yield didn’t resume.
I would’ve liked to share the project but its private and I couldn’t reproduce it again to create a example project after the fact, but that output is weird right?.
IHate | 2021-06-19 07:00