#Yield() does not work

3 messages · Page 1 of 1 (latest)

flint rock
#

The issue is that the signal is emitted immediately after you call combat_step()

as a result, you then enter the yield and combat_step_finished has already been emitted

#

only yield if you actually need to yield

mortal vale
#

This is the simplified code, the larger code is:

func combat_step(is_player_attacking : bool, actor2 : Texture) -> void:
    actor_two.texture = actor2
    if is_player_attacking:
        animator_actor_one.play("hit_left")
        timer.start()
        yield(timer, "timeout")
        animator_actor_two.play("get_hit_right")
        yield(animator_actor_two, "animation_finished")

    elif not is_player_attacking:
        animator_actor_two.play("hit_right")
        timer.start()
        yield(timer, "timeout")
        animator_actor_one.play("get_hit_left")
        yield(animator_actor_one, "animation_finished")
    emit_signal("combat_step_finished")```


The exact issue that I am having in my game is that my dialogue is triggered before end of my combat. This function is 3 functions deep so I wanted to try and keep it readable.

The above gets called by:

func _combat_step(is_player_attacking : bool, enemy : Resource, player: Resource, enemy_texture : Texture) -> void:

character_panel.combat_step(is_player_attacking, enemy_texture)

yield(character_panel, "combat_step_finished")

if(is_player_attacking):
    enemy.health -= player.attack
else:
    player.health -= enemy.attack
emit_signal("combat_step")