【发布时间】:2016-04-01 07:46:37
【问题描述】:
每当我尝试运行我的代码时,我都会经常收到此错误:
RuntimeError: maximum recursion depth exceeded while calling a Python object
我对为什么会发生这种情况感到很困惑,我试图制作一个画面并不断向下移动屏幕,作为玩家必须躲避的对象,如果命中被“杀死”(仍然添加碰撞) .当我开始得到错误是垃圾邮件外壳:
File "C:\Users\John\Desktop\Michael\V'Room External\GAME_MAIN_.py", line 195, in movement
fallingObject()
File "C:\Users\John\Desktop\Michael\V'Room External\GAME_MAIN_.py", line 206, in fallingObject
movement()
File "C:\Users\John\Desktop\Michael\V'Room External\GAME_MAIN_.py", line 160, in movement
print(x)
File "C:\Python34\lib\idlelib\PyShell.py", line 1352, in write
return self.shell.write(s, self.tags)
RuntimeError: maximum recursion depth exceeded while calling a Python object
相关代码为:
def movement():
crashed = False
while not crashed:
print(x)
...
if x < -10:
x = -10
else:
if x > 490:
x = 490
else:
fallingObject()
def fallingObject():
global w
w = 20
global o_x
o_x = random.randrange(0,width)
objectSpawn = True
while objectSpawn:
movement()
...
【问题讨论】:
-
如何创建一个最小、完整、可验证的示例:stackoverflow.com/help/mcve