“ UnboundLocalError:分配前引用了本地变量'score'

时间:2019-10-26 01:51:05

标签: python python-3.x syntax pygame syntax-error

我目前正在学习python,以及如何使用Pgzrun和Pygame创建游戏。程序要做的就是用键盘移动actor(在这种情况下为Fox)。当他与硬币碰撞时,它将使得分增加+10。在没有时间用完之前,您需要7秒才能完成游戏。但是,当演员与硬币碰撞时,程序将关闭,并在命令提示符中显示:

有人可以向我解释这是什么意思吗?如果是这样,我该如何解决?

pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
 File "c:\users\offic\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
   "__main__", mod_spec)
 File "c:\users\offic\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
   exec(code, run_globals)
 File "C:\Users\offic\AppData\Local\Programs\Python\Python37\Scripts\pgzrun.exe\__main__.py", line 7, in <module>
 File "c:\users\offic\appdata\local\programs\python\python37\lib\site-packages\pgzero\runner.py", line 93, in main
   run_mod(mod)
 File "c:\users\offic\appdata\local\programs\python\python37\lib\site-packages\pgzero\runner.py", line 113, in run_mod
   PGZeroGame(mod).run()
 File "c:\users\offic\appdata\local\programs\python\python37\lib\site-packages\pgzero\game.py", line 217, in run
   self.mainloop()
 File "c:\users\offic\appdata\local\programs\python\python37\lib\site-packages\pgzero\game.py", line 252, in mainloop
   update(dt)
 File "c:\users\offic\appdata\local\programs\python\python37\lib\site-packages\pgzero\game.py", line 194, in <lambda>
   return lambda dt: update()
 File "coin_collector.py", line 44, in update
   score = score + 10
UnboundLocalError: local variable 'score' referenced before assignment```

0 个答案:

没有答案