How would I go about getting a unit's health?

Hi all!

I’m fairly new to Terminal and as such i’m still learning all the functions and stuff.
I got my algo to detect where all my destructors are placed but my main issue right now is determining the health of those units. How could I go about reading their health?


example for checking corner piece on whether it exists and what the stability would be:

if game_state.contains_stationary_unit([27,13]):
    unit = game_state.game_map[27,13][0]
    stability = unit.stability

Excellent suggestion, thanks

1 Like

You can use preformatted text! All you need to do is insert 4 spaces as I do below:

def foo():

Hope this helps in the future!


@kkroep Thank You so Much!!! I have a questions though… what does the [0] signify?
Also how would I go about debugging things like determining values and printing them out to the console?

@kevin Thanks for the tip on how to format code! :slight_smile:

You get a list of all units on that square. For example you could get a list of 10 different pings. You already check if there exists a stationary unit, at which point there will be only one unit, but still it returns a list with one unit, not the unit itself. By picking the first element of that list you get the unit you want. Actually the code is pretty well documented. Look in the file for the function used, and it will make more sense.

Debugging can be done with:

if game_state.contains_stationary_unit([27,13]):
    unit = game_state.game_map[27,13][0]
    stability = unit.stability
    gamelib.debug_write('stability of corner unit is {}'.format(stability))

If that is not enough info to find out things yourself, maybe it is a good idea to look up some python tutorials. My recommendation for a quick lookup would be

1 Like

Ah ok! So the [0] like an array of units on that square… So for defensive units it will always be 0.

Also Thank You for the example on debugging :slight_smile:
I have a C++ background so some things are pretty weird :smiley:

Thanks y’all!


P.S. That learnxiny is really cool thx for the tip!!

1 Like