Problem with get_sprite_frames() in tutorial

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

Hello!
I’m trying to get though tutorial - 2D game on official site
I’m stuck at this step:

First, we get the list of animation names from the AnimatedSprite2D's frames property. This returns an Array containing all three animation names: ["walk", "swim", "fly"]

The code for this step:

func _ready():
$AnimatedSprite2D.play()
var mob_types = $AnimatedSprite2D.get_sprite_frames().get_animation_names()
$AnimatedSprite2D.animation = mob_types[randi() % mob_types.size()]

Link: https://docs.godotengine.org/en/stable/getting_started/first_2d_game/04.creating_the_enemy.html

So my problem is that it doesn’t suggest get_sprite_frames() on a dropdown list when I type. It’s just not there. I have no idea what I’m doing wrong. The only idea is that it’s about version - I’m using 4.0. Documentation should be up-to-date, but maybe it’s not?

:bust_in_silhouette: Reply From: jgodfrey

Hmmm… Looks like a lot of the node property setter/getter functions are no longer offered by the code hinting system. I assume that was a conscious decision (perhaps on the way to deprecation?) but I’m not really sure.

A few things. First get_sprite_frames() should still work if you just add it to your code (without the hint). Also, it’s just the getter for the sprite_frames property, which you could use instead (and will get code hints for that).

It works, actually!
Thank you.

I saw sprite_frames on the list, but I don’t know how to use it instead, sadly.

Yamarin | 2023-03-20 21:40

Great - glad it works. And, for reference, the above code using direct property access (so, without the getter), would look like:

$AnimatedSprite2D.sprite_frames.get_animation_names()

jgodfrey | 2023-03-20 22:02

That helped a lot. Now I get it!
Thanks a lot :slight_smile:

Yamarin | 2023-03-21 20:07