Cant get unit_type

def get_enemy_encryptors(self, game_state):
            global his_locations
            encryptor_locations = []
            for location in his_locations:
                unit = game_state.contains_stationary_unit(location)
                if unit.unit_type == ENCRYPTOR:
                    encryptor_locations.append(location)
            return encryptor_locations  

thats my code and this is the error I’m getting:

‘bool’ object has no attribute ‘unit_type’

I was sure this works, why doesn’t it? Can anyone help?

the variable “his_locations” is just a list of the locations on my opponents side

contains_stationary_unit returns a bool (hence the error). To access the game unit at a location, use the contains function in an if statement (to make sure something’s there) then inside of that if statement access game_state.game_map[location][0] to get the unit. The [0] is to access the first element in the stack of game units at a location, which is how game_map stores units.

1 Like

Great, thanks