is_shooting = []
is_shooting.append(False)
ShootWeapon(0)
def ShootWeapon(wep_num):
is_shooting[wep_num] = True
我得到一个奇怪的错误,其中python告诉我bool对象不支持项目分配,我不知道为什么。
完整追溯
Traceback (most recent call last):
File "C:\Users\Kian\Desktop\GitHub\SuperNova\Main.py", line 141, in <module>
main.InputEvents()
File "C:\Users\Kian\Desktop\GitHub\SuperNova\Main.py", line 133, in InputEvents
}[event.key]()
File "C:\Users\Kian\Desktop\GitHub\SuperNova\Main.py", line 129, in <lambda>
pg.K_a : lambda : Weapons.Weapons.ShootWeapon(0),
File "C:\Users\Kian\Desktop\GitHub\SuperNova\Weapons.py", line 107, in ShootWeapon
is_shooting[wep_num] = True
TypeError: 'bool' object does not support item assignment
答案 0 :(得分:3)
代码中的 else ,你直接将一个布尔值分配给is_shooting
全局:
>>> is_shooting = [False]
>>> is_shooting[0] = True
>>> is_shooting = True
>>> is_shooting[0] = True
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'bool' object does not support item assignment
您必须搜索代码以了解您的位置。