Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bool object does not support item assignment

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.

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
like image 563
Kian Shepherd Avatar asked Nov 01 '25 02:11

Kian Shepherd


1 Answers

Somewhere else in your code you assigned a boolean directly to the is_shooting global:

>>> 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.

like image 189
Martijn Pieters Avatar answered Nov 02 '25 17:11

Martijn Pieters