Question about The One Wizard

I was wondering why my code does not work in the level “The One Wizard” (Forest).

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        if hero.canCast("chain-lightning"):
            hero.cast("chain-lightning", enemy)
    elif enemy:
        if hero.canCast("lightning-bolt"):
            hero.cast("lightning-bolt", enemy)
    elif enemy:
        if hero.canCast("root"):
            hero.cast("root", enemy)
    elif hero.maxHealth < 82.5:
        if hero.canCast("regen", hero):
            hero.cast("lightning-bolt", hero)
    elif enemy:
        hero.attack(enemy)
    else:
        hero.moveXY(14, 34)

For some reason the hero is stuck at “if hero.canCast(“chain-lightning”):” after the first time she used chain lightning. Shouldn’t “False” be returned after the first time chain lightning was used and go on to the next elif (lightning bolt)? Thanks for your help!

First, you have a structural issue. All of your various methods of attack should be within the if enemy: conditional statement. Second, the elif hero.max.Health < 82.5: shouldn’t be in the if enemy: conditional. It needs to be tabbed back so that it’s only inside the while True: loop. Third, look closely at this and you’ll see what you missed:

elif hero.maxHealth < 82.5:
        if hero.canCast("regen", hero):
            hero.cast("lightning-bolt", hero)

Also, the hero.attack(enemy) should be last inside the if enemy: conditional to be used when all other methods of dispatching the enemy are in cool-down and not ready.

1 Like

Oh boy, quite a lot of rookie mistakes still. Thank you, this helped me a lot.