Problems on Swift Dagger

So I’m trying to beat the Swift Dagger level and I’m not sure what the issue is with my code:

while True:
enemy = hero.findNearestEnemy()
if enemy:
distance = hero.distanceTo(enemy)
if distance < hero.throwRange:
# Throw your dagger at the enemy.
hero.throw(enemy)
else:
# Attack the enemy with your bow.
hero.attack(enemy)

This is how I have it entered and for the life of me I don’t know why, but once the enemy gets close enough my hero stops attacking in any way and subsequently I die. Any suggestions would be greatly appreciated.

Could you format the code with 3 backticks " ` " or the “preformatted text”.


while True:
enemy = hero.findNearestEnemy()
if enemy:
distance = hero.distanceTo(enemy)
if distance < hero.throwRange:
# Throw your dagger at the enemy.
hero.throw(enemy)
else:
# Attack the enemy with your bow.
hero.attack(enemy)

This is how it looks to us right now, so if its a spacing problem it’d be impossible to tell. Also you should check out the FAQ sometime.

@andidv8 I am looking at this part of the code, since you seem to have issues when the enemy gets close. Is there a delay on the throwing of the daggers? (I only have the free account at the moment so I cannot check the code)

You might try adding a hero.isReady() check for the dagger to this part of the code.
if distance < hero.throwRange:

The best way to be able to learn to do this one is to do Peasant Protection and Munchkin Swarm, the process of doing them will help you to do this one.