Backwoods Standoff


#1

Having issues with Backwoods Standoff. Using Python.

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
       hero.isReady("cleave") 
       hero.cleave(enemy)
    else:
        hero.attack(enemy)

I think my problem is passing the variable through the else statement. The hero will find an enemy, cleave, and then he approaches a singular enemy and just bumps into them. I assume this is because the variable enemy has him find the nearest one but I thought hero.attack would cause him to find and attack. Can’t quite figure out how to fix it, advice is appreciated.


#2

Please hava a look at your indentation: Your else: refers to “if enemy”.

Have a look at your isReady method, too - I suppose you wanted to use it for a certain reason ;-).

Regards


#3

I think it should be

if enemy and hero.isReady("cleave")

Correct me if my solution is wrong…


#4

That’s correct but it may be more convenient to first check

if enemy:

and then set up the cleave and attack code block with the if hero.isReady("cleave"): and all that stuff, or else the hero might only cleave the enemy if one exists and cleave has finished cooling down, and spend the rest of the time doing nothing. The separate cleave code block within the if enemy statement prevents this.
Or use Luke10’s idea and do

elif enemy and not hero.isReady("cleave"):