私は、豚のゲームを作るためにpygameを使用しています。定義しようとしている2つの変数x
とy
があります。"intオブジェクトは添え字が付いていません"として置かれた非intオブジェクトのエラー
def drawSnake(snakeCoords):
for coord in snakeCoords:
x = coord["x"] * CellSize
y = coord['x'] * CellSize
snake_segmentRect = pygame.draw.rect(x, y, CellSize, CellSize)
pygame.draw.rect(displaysurf, green, snake_segmentRect)
snake_segmentInnerRect = pygame.Rect(x + 4, y + 4, CellSize - 8, CellSize - 8)
pygame.draw.rect(displaysurf, green, snake_segmentInnerRect)
...とエラーが出る::私は次のようにそれを持っている
line 175, in drawSnake
x = coord['x'] * CellSize
TypeError: 'int' object is not subscriptable
を助けてください、他の同様の質問がすべてでは有用ではありません。
'snakeCoords'とは何ですか?知っていれば、それを反復するときに 'ints'を返しています。そして' coord ['x'] * CellSize'というものをインデックス化しようとします。エラーを再現するコードや希望する出力を含め、問題の*再現可能な例*を提供する必要があります。 –