[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.

2 Likes

Hi @masterpickle99, welcome to the forum :tada:
Thank you for posting, but please don’t post solutions as it’s against the point of the forum. We’re here to help people understand their code, not just to give them the answer.
Thanks
Danny

Oh. Sorry! :frowning:

It’s fine, don’t worry! :grin:
A lot of people do it when they’re new to the forum. Thanks for trying to help.
Danny

Mod edit: Solution removed (20 chars)

Hi @maxhuguenin, welcome to the codecombat discourse! :tada:
Well done for doing the level, but please could you not post solutions as it’s against the rules of the forum.
Thanks
Danny

@Deadpool198 or @maxhuguenin , could one you delete the solution?