How would I get the stability of a unit given its coordinates?
I’m aware that it’s mentioned in the docs, but I can’t seem to make it work/understand. This is what I’m using but it always returns stability as being 60, even if it’s current stability isn’t.
gamelib.unit.GameUnit(FILTER, config, player_index=None, x=-X, y=-Y)
Doing this gives me
IndexError: list index out of range
The key line here:
or an empty list if there are no units at the location.
This means you need to check and make sure there is a unit before getting the first one. So:
units = game_state.game_map[x, y] #units is now a list of all units at that location
if len(units) > 0: # make sure there are units at that location
for unit in units: # loop through all units at that location
stability = unit.stability # get that units stability
then why did you highlight the line above it?
I didn’t… That post wasn’t by me.
Awarded Isaac with badge ‘The Deciever’ for highlighting the wrong line
Thanks to both Isaac and and876584635678890. I’ve got it working now.