我正在为一个简单的游戏与我的老师写一个python (pgzero)项目,但我想对它做一些改进。在添加了一些类似于地图的内容之后,一切都很好,但是在编写了代码的下一阶段之后,它完全停止了工作。对于其他向老师开具代码的学生来说,每件事都正常工作,不幸的是,对我来说并非如此。提前感谢您的帮助。如果需要更多的项目代码,我可以共享。
终端错误:
Traceback (most recent call last):
File "C:\Users\Olek\AppData\Local\Programs\Python\Python38\lib\site-packages\pgzero\clock.py", line 168, in tick
cb()
File "C:/Users/Olek/PycharmProjects/gra_mars_alfa/gra.py", line 533, in petla_glowna
if mapa_pom[bohater_y][bohater_x] not in ob_mozna_stac:
NameError: name 'mapa_pom' is not defined如果我使用终端来运行项目终端,我会说:
PS C:\Users\Olek\PycharmProjects\gra_mars_alfa> pgzrun gra.py
pygame 2.1.0 (SDL 2.0.16, Python 3.8.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "c:\users\olek\appdata\local\programs\python\python38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\olek\appdata\local\programs\python\python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Olek\AppData\Local\Programs\Python\Python38\Scripts\pgzrun.exe\__main__.py", line 7, in <module>
File "c:\users\olek\appdata\local\programs\python\python38\lib\site-packages\pgzero\runner.py", line 77, in main
src = f.read()
File "c:\users\olek\appdata\local\programs\python\python38\lib\encodings\cp1250.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 24633: character maps to <undefined> 发布于 2022-01-27 18:43:28
我说没有定义类: mapa_pom。意味着mapa_pom不是您想要使用的
您的错误是:
NameError: name 'mapa_pom' is not defined您的代码是:
if mapa_pom[bohater_y][bohater_x] not in ob_mozna_stac:所以你的意思是:如果英雄x英雄主义者不在列表where_you_can_stand中:‘代码在这里’
if map[hero.x][hero.y] not in where_you_can_stand:
'code here'变量错误示例:
print(i)追溯(最近一次调用):File“/home/pi/most/i.py”,第1行,在打印(I) NameError:名称'i‘未定义
an_actor = Actor('not_here', anchor=('center', 'middle'))回溯(最近一次调用):File“/home/pi/mu/i.py”,第1行,在an_actor = Actor(' not _here',anchor=('center',‘中间’) NameError:未定义名称'Actor‘
如果这不起作用,请告诉我在代码中使用mapa_pom的位置,我可能会回答得更好。
https://stackoverflow.com/questions/70866689
复制相似问题