Medical Attention - Python

There is no enemy at the start. One spawns a little after, but that one doesn’t come into my Heros range.

@jka2706 is saying that you are defining the enemy at the beginning of your code. You just need to remove that and you will succeed.

Um, nearly. If you remove the line completely, you don’t define the variable at all. But there are still enemies (several of them)! So when do you want the hero to find their nearest enemy?

J.

Oh, so you will need to define it on the first line after the else.

The key detail is the variable declaration enemy = hero.findNearestEnemy() needs to be within the While True loop, or that line of code will only run once at the very beginning and never again. Normally, I like to declare the variables at the beginning of the loop then add the conditional statements to determine how I want my character to react.

while True:
    declare variable
    Check if variable has something assigned
        add a command, attack or other response dependent on how you want the character to react

One little clean up detail. The else and if at the end can be combined into an elif statement to remove one line of code.

    else:
        if enemy:
            hero.attack(enemy)
# can be condensed into below for this instance.
    elif enemy:
        hero.attack(enemy)