0

Hi there,

Ive been following a pygame tutorial from devshed (here and here) on making a small game to helpme get to grips with using pygame unfortunately ive ran into a little snag :<

I've checked and re checked the code to make sure its as given but every time i execute it i get the following error:

TypeError: 'RenderUpdates' object does not support indexing.

Im guessing its happening because the tutorial is rather old and pygame and python have been updated since it was written, to save showing you all code ive just shown the bit where the error comes from.

The error is in lines 5 and 6.

# Turn each layout row into a sprite group
    for y in xrange(len(layout)):
        group = pygame.sprite.RenderUpdates()
        for x in xrange(len(layout[y])):
            if layout[y][x]:
                group.add(layout[y][x])
            group.y = 0
            layout[y] = group

If you need more of the code or more of an explanation, let me know i'll be more than happy to post it.
Any one got any ideas???

Thanks,

Logi.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by world123space
0

Hi there,

Ive been following a pygame tutorial from devshed (here and here) on making a small game to helpme get to grips with using pygame unfortunately ive ran into a little snag :<

I've checked and re checked the code to make sure its as given but every time i execute it i get the following error:

TypeError: 'RenderUpdates' object does not support indexing.

Im guessing its happening because the tutorial is rather old and pygame and python have been updated since it was written, to save showing you all code ive just shown the bit where the error comes from.

The error is in lines 5 and 6.

# Turn each layout row into a sprite group
    for y in xrange(len(layout)):
        group = pygame.sprite.RenderUpdates()
        for x in xrange(len(layout[y])):
            if layout[y][x]:
                group.add(layout[y][x])
            group.y = 0
            layout[y] = group

If you need more of the code or more of an explanation, let me know i'll be more than happy to post it.
Any one got any ideas???

Thanks,

Logi.

I also had some problem with this tutorial. I was ok with most of the code but when it came to the program pydodge.py - in copying and pasting this it was diffcult to know if the indentat1ion was correct. So I sent an e-mail to the author and he very kindly sent me the complete pydodge.py. The program worked fine. I suggest you also write to him if you`re still interested in this.

I don`t know if I have permission to send you the whole pydodge.py however, Ill just send you the relevant section:

def loadSprites():

   global player, playerSprite

   # Find the position of the player
   colWidth = background.get_rect().width / columns
   xPlayer = colWidth / 2
   rowHeight = background.get_rect().height / rows
   yPlayer = (rowHeight * (rows - 1)) + (rowHeight / 2)

   # Load the player sprite
   playerSprite = gamesprites.Player(player, xPlayer, yPlayer)

   # Create a player sprite group
   player = pygame.sprite.RenderUpdates(playerSprite)

   # Load each object sprite
   for y in xrange(len(layout)):
      for x in xrange(len(layout[y])):
         if layout[y][x]:
            layout[y][x] = gamesprites.Object(objects[layout[y][x] - 1], (colWidth * (x)) + (colWidth / 2))

   # Turn each layout row into a sprite group
   for y in xrange(len(layout)):
      group = pygame.sprite.RenderUpdates()
      for x in xrange(len(layout[y])):
         if layout[y][x]:
            group.add(layout[y][x])
      group.y = 0
      layout[y] = group

You can see from this that your indentation in the last two lines is different from this.
Hope this is of help.
( Note also, the indentation of the above is ( an unusual ) 3.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.