SuperDisk
SuperDisk

Reputation: 2840

Pygame group update takes no arguments

I've read up on similar problems elsewhere, but it says just to add 'self' to the function definition. When I check the file it's self, it actually already has the self keyword first! Here's the traceback:

Traceback (most recent call last):
  File "C:\Users\Brenda\Documents\The Nick Folder\Mobile Fortress War 3\MFWRT3 - TileClass test\Title.pyw", line 142, in <module>
    SelectServer.main()
  File "C:\Users\Brenda\Documents\The Nick Folder\Mobile Fortress War 3\MFWRT3 - TileClass test\SelectServer.pyw", line 44, in main
    Main.mainloop()
  File "C:\Users\Brenda\Documents\The Nick Folder\Mobile Fortress War 3\MFWRT3 - TileClass test\Main.pyw", line 72, in mainloop
    globals.alltiles.update()
  File "C:\Python32\lib\site-packages\pygame\sprite.py", line 462, in update
    s.update(*args)
TypeError: update() takes no arguments (1 given)

And I called it like this:

globals.alltiles.update()

Can anyone help out?

Upvotes: 1

Views: 1020

Answers (2)

user2365959
user2365959

Reputation: 11

i am a bit late but it's probably because of improper declaration of the update method for each card (which i assume is subclassing pygame.sprite.Sprite)

it should be declared as "def update(self)" and not "def update()"

Upvotes: 1

龚元程
龚元程

Reputation: 417

Without code to debug it's going to be a guessing game, but for future reference, sprite groups are created like this:

#first create a sprite class
class Card(pygame.sprite.Sprite):
    def __init__(self,img,pos):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load(os.path.join('img','cards', img))
        self.rect = self.image.get_rect()
        self.rect.center = pos

#then create a group
mycards = pygame.sprite.Group()

#then add a sprite to the group
holders.add(Card('ace_spade.jpg',coord))

Upvotes: 0

Related Questions