TypeError: 'NoneType' object is not iterable

Hello i am trying to see if there are and distructors at a location and I get this,

anyone know how to fix this?

units = game_state.game_map[[27,14],[26,14],[25,14],[24,14],[23,14],[22,14],[26,15],[25,15],[24,15],[23,15],[22,15],[25,16],[24,16],[23,16],[22,16],[24,17],[23,17],[22,17],[23,18],[22,18]]
			for unit in units:
				gamelib.debug_write(f"rigth: {unit.unit_type}")
				if unit.unit_type == 'DESTRUCTOR':
					destructors_count_rigth = destructors_count_rigth + 1

and this is what i get

TypeError: ‘NoneType’ object is not iterable

I Can’t figure out whats wrong

I don’t think what you are doing is possible, try something like this:

location_list = [[27,14],[26,14],[25,14],[24,14],[23,14],[22,14]]
for location in location_list:
    #since you're looking for destructors, which is a stationary unit
    unit = game_state.contains_stationary_unit(location)
    #check if there is even any unit on that location
    if unit:
        #check if it is a destructor
        if unit.unit_type == DESTRUCTOR:
            #do other stuff

Hope that helps, sorry I’m not that good at explaining what exactly you did wrong, maybe someone else can clear that part up?

1 Like


This method takes only one location game_map[x,y]
if there is no filed or the input is wrong game map will return None (NoneType)
then when you try to itterate / for loop over None … you get the mentioned error

TypeError: ‘NoneType’ object is not iterable

Like in the example @IWannaWin provided, first create the list of locations, and ask the map for each one,
make sure to check if you get an actual unit.

1 Like

Aha thanks guys =)

i em learning a lot from you and this helped me very much

Thanks @IWannaWin nad @Demorf