jsadd
jsadd

Reputation: 19

getting error in pygame 'pygame.surface' object is not subscript able

I'm getting this error when running pygame.Surface object is not subscriptable. I have tried looking at similar code but still to green to place where I went wrong.

if I remove all "hit" lines it works. I want to insert an image for a hit function it will run till SPACE is hit.

 elif self.isHitRight:
            win.blit(hitRight[self.hitCount], (self.x, self.y))
            self.hitCount += 1
        elif self.isHitLeft:
            win.blit(hitLeft[self.hitCount], (self.x, self.y))
            self.hitCount += 1

Upvotes: 1

Views: 280

Answers (1)

Jack Aidley
Jack Aidley

Reputation: 20107

Your error object is not subscriptable means that you have tried to use an array operator (that is you've done something like x[y]) on an object that does not support it. The only objects you're doing this on are hitLeft and hitRight, which I presume are pygame.Surface objects. pygame.Surface objects don't support this.

Most likely you originally needed to define hitLeft and hitRight as arrays of pygame.Surface objects.

Upvotes: 1

Related Questions