Python surface error? Why?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Trolkar8
    New Member
    • Nov 2011
    • 4

    Python surface error? Why?

    I have got a problem in my script. i am trying to make an rpg game(Yeah yeah i just started...). When i run the program and push any of the arrow keys i get an error. Why ?
    The errors look like the followings
    Code:
                elif event.key == pygame.K_DOWN:
                    y = y - 20
                    screen.blit(player[x, y])
    Code:
       def Walk(self, x, y):
            pygame.draw.rect(screen, [0,255,0],[0, 0, 480, 640])
            self.image = pygame.image.load(player_images[self.angle])
            screen.blit(self.image[x, y])
            if self.angle == 0:
                y = y - 20
            elif self.angle == 1:
                x = x + 20
            elif self.angle == 2:
                y = y + 20
            elif self.angle == 3:
                x = x - 20
            pygame.display.flip()
    The syntax error:
    Code:
    screen.blit(self.image[x, y])
    TypeError: 'pygame.Surface' object is unsubscriptable
    Script terminated.
    Last edited by Trolkar8; Nov 9 '11, 09:13 PM. Reason: forgot something
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You received that error because self.image is not scriptable. A list or tuple is scriptable. It's possible an attribute of self.image is scriptable.

    Comment

    Working...