while True:
enemy= hero.findNearestEnemy()
if hero.health < 50:
hero.moveXY(34, 35)
else:
if enemy:
hero.bash(enemy)
hero.attack(enemy)
hero.attack(enemy)
Hi I need some help on clash of clones level. I have been stuck on this for more than a year and have constantly been looking at help for this level. I finally decided to post this rather simple code. The problem with this is that for some reason, my hero starts saying “But it’s Dead” in the middle and dies.
The combination of these three lines is causing the problem. You have identified one enemy, and at some point before the last attack the enemy dies, but your code is telling your hero to attack. Since there isn’t an enemy, your hero says “But it’s Dead”.
if enemy:
hero.bash(enemy)
hero.attack(enemy)
hero.attack(enemy)
Also, the Bash has a Cooldown period of 6 seconds which means you can’t use it until the time is up. With no check on the cooldown like if hero.isReady("bash"): your hero waits until the 6 seconds is up to continue the code. If the hero isn’t ready, do a regular attack or shield.