Why doesnt this work? checking firewall stability

So i want to check if one single filter has half or less of its health and this is my code:

if (game_state.game_map[26,12].stability / game_state.game_map[26,12].max_stability)*100 < 50:
game_state.attempt_remove([26,12])

It keeps crashing though, can someone halp me please?

the return is a list of firewalls, not a single one. Because it also can be used to get multiple information units on the same tile. In order to make it work you need to do:

if game_state.contains_stationary_unit(location) == True: # first check whether there is a unit in the first place
if game_state.game_map[location][0].stability < 50: # retrieve the unit and compare its stability
game_state.attempt_remove(location) # remove the unit

That should work

Thanks for the reply, but Im still havong a bit of trouble

So i have this now:

if game_state.contains_stationary_unit([26, 12]) == True: # first check whether there is a unit in the first place
if game_state.game_map[[26, 12]][0].stability < 50: # retrieve the unit and compare its stability
game_state.attempt_remove([26, 12]) # remove the unit

and it doesn’t throw an error but it doeant work. Nothing happens even when the filter at 26, 12 gets damged beyond 50%

Okay this piece of code works for sure because I used this myself in older algos:

    firewall_locations = game_state.game_map.get_all_firewall_locations()
    for location in firewall_locations:
        unit = game_state.game_map[location][0]
        if (unit.stability < 30 and not unit.unit_type == ENCRYPTOR):
            if game_state.contains_stationary_unit(location):
                game_state.attempt_remove(location)

If you cant get it to work, then something else is wrong with your code

I would have done it this way:

unit = game_state.contains_stationary_unit(location)
if unit and unit.stability / unit.max_stability < 0.5:
    game_state.attempt_remove(location)
3 Likes

ok thanks now it works