0
class AnimateSprite(pygame.sprite.Sprite):

    def __init__(self, sprite_name):
        super().__init__()
        self.image = pygame.image.load(f'assets/{sprite_name}.png')
        self.current_image = 0 
        self.images = animations.get(sprite_name)
        
    def animate(self):

        self.current_image += 1

        if self.current_image >= 24:

            self.current_image = 0

        self.image = **self.images**[self.current_image]

def load_animation_images(sprite_name):

    images = []

    path = f"assets/{sprite_name}/{sprite_name}"

    for num in range(1,24):
        image_path = path + str(num) + '.png'
        images.append(pygame.image.load(image_path))

        return images

i am trying to code an animation code in pygame for a game but i have this error:

Object of type "None" is not subscriptablePylancereportOptionalSubscript
(variable) images: list[Unknown] | None

I am accualy using VSC and Python 3.11.3 64bit installed in Microsoft store

Paul M.
  • 10,481
  • 2
  • 9
  • 15
  • 1
    Exactly the same question I have seen here many times. The problem is always the same. `animations.get(sprite_name)` returns `None` because no sprites were loaded because the working director was not set. Also see [Could not open resource file, pygame error: "FileNotFoundError: No such file or directory."](https://stackoverflow.com/questions/58177145/could-not-open-resource-file-pygame-error-filenotfounderror-no-such-file-or) – Rabbid76 May 19 '23 at 13:34
  • Just add `import os` and `os.chdir(os.path.dirname(os.path.abspath(__file__)))` – Rabbid76 May 19 '23 at 13:38
  • where a paste youre code ?in path ? – le big boss May 19 '23 at 13:42
  • IndexError: list index out of range – le big boss May 19 '23 at 13:47
  • `if self.current_image >= len(self.images):` instead of `if self.current_image >= 24:` – Rabbid76 May 19 '23 at 13:48

0 Answers0