No idea how to fix this error

i dont know how im supposed to fix this error:

Player 1 Errors:

Random seed: 4877006227868190628
---------------- Starting Your Algo --------------------
Configuring your custom algo strategy…
Performing turn 0 of your custom algo strategy
Traceback (most recent call last):
File “//algo_strategy.py”, line 312, in
algo.start()
File “/gamelib/algocore.py”, line 74, in start
self.on_turn(game_state_string)
File “//algo_strategy.py”, line 56, in on_turn
self.starter_strategy(game_state)
File “//algo_strategy.py”, line 86, in starter_strategy
game_state.attempt_spawn(INTERCEPTOR,location_options.remove(spawn_loc),1)
File “/gamelib/game_state.py”, line 374, in attempt_spawn
if type(locations[0]) == int:
TypeError: ‘NoneType’ object is not subscriptable

list.remove(item) returns None, not the updated list, so “locations” is unexpectedly None in attempt_spawn, causing the error.

1 Like

The error is self-explanatory. You are trying to subscript an object which you think is a list or dict, but actually is None (i.e: the object has no value). This means that you tried to do:

None[something]

Here you attempted to index an object that doesn’t have that functionality. You might have noticed that the method sort() that only modify the list have no return value printed – they return the default None. This is a design principle for all mutable data structures in Python.

This ‘NoneType’ object is not subscriptable is the one thrown by python when you use the square bracket notation object[key] where an object doesn’t define the getitem method.