1

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
lucidbrot
  • 5,378
  • 3
  • 39
  • 68
jsadd
  • 19
  • 2
  • 2
    Welcome to StackOverflow! Please make sure that, when asking a question, you provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). This will help us figure out where the problem might be in your code. – Kind Stranger Oct 27 '18 at 03:04
  • 1
    Can you also please provide the full error trace? – Kind Stranger Oct 27 '18 at 03:05
  • This message likely means that the `[]` operator is not defined for `hitRight` – lucidbrot Oct 27 '18 at 11:53
  • Possible duplicate of [In Python, what does it mean if an object is subscriptable or not?](https://stackoverflow.com/questions/216972/in-python-what-does-it-mean-if-an-object-is-subscriptable-or-not) – lucidbrot Oct 27 '18 at 11:54

1 Answers1

1

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.

Jack Aidley
  • 19,439
  • 7
  • 43
  • 70