Error calling method from animation finished. How can i fix this?

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

extends KinematicBody2D

var movement = Vector2();
var up = Vector2(0, -1);
var SPEED = 150;
var isAttacking = false;
onready var animationPlayer = $AnimationPlayer

func _process(delta):

if Input.is_action_pressed("ui_right") && isAttacking == false:
	movement.x = SPEED;
	$Sprite.flip_h = false;
	$AnimationPlayer.play("Running")
elif Input.is_action_pressed("ui_left") && isAttacking == false :
	movement.x = -SPEED;
	$Sprite.flip_h = true;
	$AnimationPlayer.play("Running")
else:
	movement.x = 0;
	if isAttacking == false:
		$AnimationPlayer.play("Idle");
	

if Input.is_action_just_pressed("a"):
	isAttacking = true
	$AnimationPlayer.play("Attack 1")
if Input.is_action_just_pressed("s"):
	$AnimationPlayer.play("Attack 2")
	isAttacking = true;
if Input.is_action_just_pressed("d"):
	$AnimationPlayer.play("Attack 3");
	isAttacking = true;
movement = move_and_slide(movement, up * delta);

func _on_AnimationPlayer_animation_finished():
if $AnimationPlayer.animation == “Attack 1”:
isAttacking = false;

:bust_in_silhouette: Reply From: yrtv
if $AnimationPlayer.animation == "Attack 1":

Animation is finished you AnimationPlayer have no animation to compare.

Edit:

func onAnimationPlayeranimationfinished():
if $AnimationPlayer.animation == "Attack 1":
isAttacking = false;

Is this connected to

animation_finished ( String anim_name )

Notifies when an animation finished playing.

Then you already received animation name

func onAnimationPlayeranimationfinished(anim):
    if anim == "Attack 1":
    isAttacking = false;

Edit 3
Docs AnimationPlayer — Godot Engine (stable) documentation in English

Thanks for the help

Viaas | 2021-02-07 19:32