Help for a level please

Can someone help me with the level: seige of stoneholde, my code is correct but everytime my hero dies.
This is my code:
while True:
enemy = hero.findNearestEnemy()
flag = hero.findFlag(“green”)
if flag:
hero.pickUpFlag(flag)
elif enemy and hero.isReady(“cleave”):
hero.cleave(enemy)
elif enemy:
hero.attack(enemy)

1 Like

There is no theoretically “correct” code for this level as long as you have a strategy to fight the ogres. Maybe you need to get better armor.
You can also get healed by a wizard if you use hero.moveXY(19, 69) and your hero will move to a point on the map where the wizard instantly heals you. It requires slightly more advanced syntax and you probably don’t yet have access to sense stones that return your hero’s health and maxHealth, but just a tip :slight_smile:
Do you have sense stones that can do this? What gear does your hero have?

1 Like

Make sure you have good armor. I recommend getting the Deflector Shield and / or the Dragon Head and Chesplate; They serve as the ultamine barrier.

2 Likes

Pierre’s probably not that advanced unless he can simulate a ton of games and get there. :slight_smile:

1 Like

Also you do not need to call elif enemy twice. Just call elif enemy once and then set up a separate code block with the cleave and attack abilities.

1 Like

thx everyone I will follow ur advices.

1 Like

Make sure that in the future, you format your code according to the FAQ.
https://discourse.codecombat.com/faq

1 Like

My technique is that you check when your hero’s health is low:

if hero.health<hero.maxHealth/2:
    hero.moveXY(20,68)

Otherwise keep attacking:

elif enemy:
    hero.attack(enemy)

this code will tell your hero to move to move to the x to get healed when your hero’s health is low. And also tells your hero to attack the target when your hero’s hp is higher. I hope this helps!

2 Likes

This problem has already been solved.

1 Like

Thanx for your advice I will try it. it worked

1 Like