我正在使用pygame制作蛇游戏,并且我有两个变量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
请帮帮忙,其他类似的问题是没有帮助的。
什么是'蛇协会'?当然,它会在你遍历它时返回'ints',然后尝试索引这些:'coord ['x'] * CellSize',你期望*会发生什么?您需要提供一个*可重现的示例*,包括将重现该错误的代码以及所需的输出。 –