My code works but i don’t have enough health
You should buy better armor.
As @Serg mentioned. You should probably buy better armor.
If you have subscribed for codecombat, you should get a certain amount of gems every month.
What is wrong with my code
while True:
enemy = hero.findNearestEnemy()
if enemy:
pass # Replace this with your own code.
# Find the distance to the enemy with distanceTo.
ifdistance = hero.distanceTo(“enemy”)
# If the distance is less than 5 meters…
hero.distanceTo(“enemy”) < 5
# … if “cleave” is ready, cleave!
ready = hero.isReady(“cleave”)
hero.cleave(“enemy”)
# … else, just attack.
hero.attack(“enemy”)
did you store the distance value in ifdistance
?
In the code above you are just creating a logic statement. A logic statement by itself will not do anything. The comments ask you to create an if…then…else statement.
Do you remember how to do that?
Your code needs this control logic to make use of your logic statements.
Right now you are most likely doing everything each round:
- calculating the distance (but not using this calculation)
- trying to cleave the enemy
- trying to attack the enemy