is_shooting = []
is_shooting.append(False)
ShootWeapon(0)
def ShootWeapon(wep_num):
is_shooting[wep_num] = True
I'm getting a weird error where python is telling me that bool objects don't support item assignment and I'm not sure why.
我得到一个奇怪的错误,其中python告诉我bool对象不支持项目分配,我不知道为什么。
Full traceback
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
1 个解决方案
#1
Somewhere else in your code you assigned a boolean directly to the is_shooting
global:
在代码中的其他地方,您直接为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
You'll have to search through your code to find out where you do so.
您必须搜索代码才能找到您执行此操作的位置。
#1
Somewhere else in your code you assigned a boolean directly to the is_shooting
global:
在代码中的其他地方,您直接为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
You'll have to search through your code to find out where you do so.
您必须搜索代码才能找到您执行此操作的位置。