-1
当我运行以下游戏时,出现“意外缩进”错误,但是当您查看代码时,它完全正确。pygame中的意外缩进
错误发生在del evilGuy[-1]
。缩进是正确的,但我得到这个错误。
编辑
该代码已被修改了一下。即使现在错误发生在:del evilGuy[-1]
显示意外的缩进。
def evilMove(evilGuy):
evilCoords=[]
#deadZones=[]
#Returns either -1, 0 or 1
randomMovex=random.randrange(-1,2)
randomMovey=random.randrange(-1,2)
newCell={'x':evilGuy[0]['x']+randomMovex,'y':evilGuy[0]['y']+randomMovey}
if (newCell['x']<0 or newCell['y']<0 or newCell['x']>cellSize or newCell['y']>display_height/cellSize):
newCell={'x':display_width/(2*cellSize),'y':display_height/(2*cellSize)
del evilGuy[-1]
evilCoords.append(newCell['x'])
evilCoords.append(newCell['x'])
deadZones.append(evilCoords)
evilGuy.insert(0,newCell)
解决
错误是在功能evilMove缺少 '}'。 Solutiuon给出如下。
def evilMove(evilGuy):
evilCoords=[]
#deadZones=[]
#Returns either -1, 0 or 1
randomMovex=random.randrange(-1,2)
randomMovey=random.randrange(-1,2)
newCell={'x':evilGuy[0]['x']+randomMovex,'y':evilGuy[0]['y']+randomMovey}
if (newCell['x']<0 or newCell['y']<0 or newCell['x']>cellSize or newCell['y']>display_height/cellSize):
newCell={'x':display_width/(2*cellSize),'y':display_height/(2*cellSize)} # Here It's missing '}'
del evilGuy[-1]
evilCoords.append(newCell['x'])
evilCoords.append(newCell['x'])
deadZones.append(evilCoords)
evilGuy.insert(0,newCell)
你也许使用Tabs和Spaces混合? – xXliolauXx
我觉得@xXliolauXx没错。对于测试,这只是复制你的代码行,它显示你的空间点和标签线。 – GrvTyagi
@xXliolauXx,没有我没有混合制表符和空格。上面的代码正是我在我的代码。 –