0 votes

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 physicsprocess(delta):
controls
loop()
movementloop()
spritedir
loop()

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

func controlsloop():
var LEFT = Input.is
actionpressed("uileft")
var RIGHT = Input.isactionpressed("uiright")
var UP = Input.is
actionpressed("uiup")
var DOWN = Input.isactionpressed("ui_down")

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

func movementloop():
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 animswitch(animation):
var newanim = str(animation,spritedir)
if $anim.current
animation != newanim:
$anim.play(newanim).

in Engine by (25 points)

1 Answer

0 votes

seems that you wrote the wrong address to your node

if $anim.currentanimation != newanim:

did you reoganiced your Node-tree maybe?

by (67 points)

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

Thank you.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.