Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Challenge : The One Wizard

Hi there.

I’m having trouble with hint 3 in the challenge trying to identify bigger “ogres” by .
if enemy.type == “ogres”
Any advice would be appreciated and tips on how I can present my coding errors would also be helpful.

Change that to:
if enemy.type == "ogre":

Cheers

That solved the first problem now I’m stuck with getting hero to move if “ogre”
and casting “regen”

while True:
enemy = hero.findNearestEnemy()
if enemy:
    distance = hero.distanceTo(enemy)
    if enemy and enemy.type == "ogre":
        hero.moveXY(10, 36)  
    elif distance < 10 and hero.canCast("chain-lightning", enemy):
        hero.cast("chain-lightning", enemy)
        
    elif enemy and hero.canCast("lightning-bolt", enemy):
        hero.cast("lightning-bolt", enemy)
        
    elif enemy:
        hero.attack(enemy)
    elif hero.canCast("regen", hero) and hero.health < 50:
        hero.cast("regen", hero)

-This kinda works but would like to do better if you could point out what i need to work on

Change it to:

if enemy:
        distance = hero.distanceTo(enemy)
        if enemy.type == "ogre":
            hero.moveXY(10, 36)  
        elif distance < 10 and hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
            
        elif hero.canCast("lightning-bolt", enemy):
            hero.cast("lightning-bolt", enemy)
            
        
            
        elif hero.canCast("regen", hero) and hero.health < 50:
            hero.cast("regen", hero)
        else:
            hero.attack(enemy)

You don’t need to check for an enemy twice. It also seems like you forgot to indent inside the while True loop.

1 Like