Reputation: 19
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
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