Godot Version
4.2
Question
Hi, I’m pretty new to programming in general, sorry if it’s a stupid question.
I’m trying to use GDscript as a statically typed language.
consider this code:
if direction.x > 0:
get_node("AnimatedSprite2D").play("steering_right")
Since I enabled the warnings in the editor, i get this warning:
The method "play()" is not present on the inferred type "Node" (but may be present on a subtype).
<GDScript Error>UNSAFE_METHOD_ACCESS
In this case, how would i tell the compiler that “AnimatedSprite2D” is an AnimatedSprite2D node? I don’t want it to infer what it is.
I tried
get_node("AnimatedSprite2D": AnimatedSprite2D).play("steering_right")
But it won’t accept it, it says
Line 12:Expected closing ")" after call arguments.
Line 12:Expected end of statement after expression, found ":" instead.
So obviously it’s not the way to do it.
I tried reading the Docs but I cannot figure it out.
Any help?
Thanks!!!