Character 2D Error Code

Hello everyone,
I would like to understand what I did wrong in the code. I got this message:“Identifier “sprite” not declared in the current scope.” Should I enter a new variable?

Thanks in advance for the answers

1 Like

Could you maybe show us a sreenshot of your code?
But just from this, it seems like you use the var ‘sprite’ without declaring it beforehand.

What you could do:

@onready var sprite : Sprite2D = get_node(“your_sprite”)
#remember to select the wanted sprite instead of #“your_sprite”

You could also use:

$Sprite2D instead of get_node(“your_sprite”)

Hope this helps

Edit: it might also be that you declared it already, just not in the correct function, this is just not possible to know without seeing the code

1 Like

thanks for the reply now i will attach the images of the code

Hey, thank you for your reply!
I see the issue now. You use ‘sprite’ without having it declared before. This is because you declared ‘sprite_2D’
Either You use ‘sprite_2D’ or change the variable name to ‘sprite’.

Other than that, it looks pretty good

2 Likes

Your variable name is sprite_2D not sprite.

2 Likes

You save my day. Thank’s a lot

1 Like

Great to hear that, have an awesome day!

1 Like

you too

1 Like