0

So the problem I'm encountering is that I get an error saying that Player has no attribute run_dust_particles when I just set the function there.

Code for run_dust_particles:

def run_dust_animation(self):
        if self.status == 'run' and self.on_ground:
            self.dust_frame_index += self.dust_animation_speed
            if self.dust_frame_index >= len(self.dust_run_particles):
                self.dust_frame_index = 0

            dust_particle = self.dust_run_particles[int(self.dust_frame_index)]

            if self.facing_right:
                pos = self.rect.bottomleft
                self.display_surface.blit(dust_particle, pos)

Code where I'm calling it:

def update(self):
    self.get_input()
    self.get_status()
    self.animate()
    self.run_dust_animation()

Update() call I am doing:

self.player.update()

Full error message starting at traceback:

Traceback (most recent call last):
File "C:\Users\Daniel\Desktop\PlatformerGame.py", line 28, in <module>
level.run()
File "C:\Users\Daniel\Desktop\level.py", line 98, in run
self.player.update()
File "C:\Users\Daniel\AppData\Local\Programs\Python\Python310\lib\site-packages\pygame\sprite.py", line 
539, in update
sprite.update(*args, **kwargs)
File "C:\Users\Daniel\Desktop\player.py", line 134, in update
self.run_dust_animation()
AttributeError: 'Player' object has no attribute 'run_dust_animation'
Daniel
  • 15
  • 1
  • 7
  • Can you show an example of a `update()` call that you are doing? – ihavenoidea Mar 02 '22 at 02:27
  • self.player.update() – Daniel Mar 02 '22 at 05:00
  • Are you sure that this method is actually part of the `Player` class? If it's indented exactly as shown here, then it's a top-level function, not a method at all. Another possibility is that it's somehow getting called before the definition has been reached - we can't tell, because you haven't shown us a [mcve], nor have you shown us the full traceback message. – jasonharper Mar 02 '22 at 05:12
  • yes, it's part of the player class. Full traceback message should now be edited in – Daniel Mar 02 '22 at 05:43
  • Is the indentation of `def run_dust_animation(self):` correct? – Rabbid76 Mar 02 '22 at 14:56
  • @Rabbid76 -- I'm such an idiot, that was it. Thanks! – Daniel Mar 03 '22 at 01:20

0 Answers0