我已經找過這樣的其他案例,但沒有一個適用於我....或者如果他們這樣做,我不明白如何。TypeError:'int'對象不是可訂閱的
我所試圖做的是通過一個二維數組(這一點)來篩選:
blocks = [
[ [0], [0], [0], [0], [0], [0], [0], [0], [0], [0] ],
[ [0], [0], [0], [0], [0], [0], [0], [0], [0], [0] ],
[ [0], [0], [0], [0], [0], [0], [0], [0], [0], [0] ],
[ [0], [0], [0], [0], [0], [0], [0], [0], [0], [0] ],
[ [0], [0], [0], [0], [0], [0], [0], [0], [0], [0] ],
[ [0], [0], [0], [0], [0], [0], [0], [0], [0], [0] ],
[ [0], [0], [0], [0], [0], [0], [0], [0], [0], [0] ],
[ [0], [0], [0], [0], [0], [0], [0], [0], [0], [0] ],
[ [0], [0], [0], [0], [0], [0], [0], [0], [0], [0] ],
[ [0], [0], [0], [0], [0], [0], [0], [0], [0], [0] ]
,並找出當前的部分是什麼。對不起,如果我的代碼有點草率,我是python的新手。這是我的代碼(部分),
def drawBlock():
for blockL1 in blocks:
for blokL2 in blocks:
if blocks[blockL1[blockL2[1]]] == 0:
pygame.draw.rect(screen, (0, 255, 255), Rect((blockL1 * 32, blockL2 *32), (32, 32)))
pygame.draw.rect(screen, color, Rect(i * 32,))
global blockL2
blockL2 += 1
global blockL1
blockL1 += 1
您的塊實際上是一個3維數組。移除每個「0」周圍的'[]'。 – GWW