Invalid get index 'current animation'(on base: 'null instance')

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

I don’t know why this error appears:
Invalid get index ‘current animation’ (on base: ‘null instance’)

any ideas?
Thank you

extends KinematicBody2D

const SPEED = 70

var movedir = Vector2(0,0)
var spritedir = “down”

func _physics_process(_delta):
controls_loop()
movement_loop()
spritedir_loop()

if movedir != Vector2(0,0):
	anim_switch("idle")

func controls_loop():
var LEFT = Input.is_action_pressed(“ui_left”)
var RIGHT = Input.is_action_pressed(“ui_right”)
var UP = Input.is_action_pressed(“ui_up”)
var DOWN = Input.is_action_pressed(“ui_down”)

movedir.x = -int(LEFT) + int(RIGHT)
movedir.y = -int(UP) + int(DOWN)

func movement_loop():
var motion = movedir.normalized() * SPEED
move_and_slide(motion, Vector2(0,0))

func spritedir_loop():
match movedir:
Vector2(-1,0):
spritedir = “left”
Vector2(1,0):
spritedir = “right”
Vector2(0,-1):
spritedir = “up”
Vector2(0,1):
spritedir = “down”

func anim_switch(animation):
var newanim = str(animation,spritedir)
if $anim.current_animation != newanim:
$anim.play(newanim).

:bust_in_silhouette: Reply From: gruen

seems that you wrote the wrong address to your node

if $anim.currentanimation != newanim:

did you reoganiced your Node-tree maybe?

I’ll check, although I think the script code was well written.
Maybe I changed some place folder …

Thank you.

David_sun | 2019-10-17 17:10