a single line of code inside of a function is not played, and that confuses me....

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

Hi there I am glad to be here. I am new to Godot and normally I come from the theater and I am doing 3D stuff. But now I tried out this game engine, and I love it. But I have a problem since two days, as written above. Although a function is working, and the debugger has no warnings or so, the engine “jumps” one code - line. The code is this one:

func toedlich():
if is_alive == true:
yield($AnimatedSprite, “animation_finished”)
is_alive = false

everything is executed, except the line with the AnimatedSprite. It even holds the yield for the time, the animation would need to run. But it does not play it… I am absolutely confused. If there are any ideas, thank you very very much…
(Sorry for the English, its not my mother language…)

i suppose the issue is in the node, not the code, what parameter are you trying to animate?

Andrea | 2021-03-17 16:20

the node is a kinematic body. maybe it is better to understand, if I post the whole code:
for explanation: “Flint” is the player

extends KinematicBody2D

export var gravity = 400
var movement = Vector2()
var UP_Vector = Vector2(0, -1)
export var speed = 200
export var jump = 250
onready var spriteFlint = $AnimatedSprite
var is_alive = true

#–> signale

func _on_HarmlosArea2D_body_entered(body: Node) → void:
is_alive = false

func _on_Hit_Box_Bomb_area_entered(area: Area2D) → void:
is_alive = false

#<— Ende signale

#-----> Physics Prozesse Flint

func _physics_process(delta):
movement.x = 0
movement.y += gravity * delta

#–> Verhindert, dass Gravitation sich multipliziert oder dass man an der Decke kleben bleibt
if is_on_ceiling() or is_on_floor():
movement.y = 0
#<-- Ende verhindert, dass Gravitation sich multipliziert oder dass man an der Decke kleben bleibt


movement = move_and_slide(movement, UP_Vector)

#<-----Ende Physics Prozesse Flint

#–> funktionen
func toedlich():
if is_alive == false:
yield(spriteFlint, “animation_finished”)
is_alive = true

func harmlos():
if is_alive == false:
yield(spriteFlint, “animation_finished”)
is_alive = true

#------> Steuerung Flint

func _check_key_input():

if Input.is_action_pressed("walk_left") && is_alive == true:
	spriteFlint.flip_h = true
	movement.x = -speed
if Input.is_action_pressed("walk_left") && is_on_floor() && is_alive == true:
	spriteFlint.flip_h = true
	movement.x = -speed
if Input.is_action_pressed("walk_right") && is_alive == true:
	spriteFlint.flip_h = false		
	movement.x = speed
if Input.is_action_pressed("walk_right") && is_on_floor() && is_alive == true:
	spriteFlint.flip_h = false		
	movement.x = speed
if Input.is_action_pressed("jump") && is_on_floor() && is_alive == true:
	movement.y = -jump
if movement.y > 10:
#if Input.is_action_pressed("up") && is_on_floor() && is_alive == true:
	#movement.y = -jump / 2
if movement.x == 0 && movement.y == 0 && is_on_floor() && is_alive == true:

#<----Ende Steuerung Flint

func die() → void:
SpielerDaten.deaths += 1

tellheim | 2021-03-17 16:31

:bust_in_silhouette: Reply From: Inces

Please check if AnimatedSprite is set to frame 0 in the editor. Sometimes people test animation in the editor and leave it on last frame, so it is impossible to see animation when calling play() form code.

It is on frame 0. I always put all the animation in a AnimatedSprite back to 0. All other animations of that sprite are played…
maybe my signals are not correct? Did I misunderstand something?

But the signals are executing the function and the function plays everything except the sprite Animation in this case… makes me confused…

tellheim | 2021-03-17 16:51

Thank you for taking the time… yes, the comments are gernan and therefore a little bit tricky.

yes, harmlos() works fine.
tödlich() does not work without yield, checked this already.

the Animated Sprite is addressed correct. Everything (Flint_Walk, Flint_Jump, Flint_Idle) plays very well.

can it be the signal? for harmlos() the signal works perfect. toedlich() ist almost the same thing but for a different enemie and with another animation…

tellheim | 2021-03-17 17:37

:bust_in_silhouette: Reply From: Andrea

(sorry, i misread your original post and i thought it was an animation player node in my previous comment)

most likely spriteFlint.play("Dummgelaufen") get blocked by the below line of code (maybe a random mouse movement?), that revert the play to idle inside checkkey_input():

if movement.x == 0 && movement.y == 0 && is_on_floor() && is_alive == true:

if this was not the reason, you need to do some debuggin:
are you sure toedlich() is actually called?
are you sure spriteFlint actually points to the correct animated sprite node?
does harmlos() works correctly?
does it works without yield?