I am having trouble with my code on this level. I am trying to find the weakest enemy and then attack that enemy but nothing is happening. PLS HELP!
# This function should go through the enemy array and find the weakest enemy
def findWeakestEnemy():
enemies = hero.findEnemies()
weakest = None
leastHealth = 99999
enemyIndex = 0
# Picking out individual enemy from the array and testing his health agains leastHealth
if enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
if enemy.health < leastHealth:
weakest = enemy
leastHealth = enemy.health
enemyIndex += 1
return
while True:
enemy = findWeakestEnemy()
if enemy:
hero.attack(enemy)
Howdy and welcome to the forum! Please repost your code, properly formatted. You can learn how here: [Essentials] How To Post/Format Your Code Correctly
Hi dedreous,
Thanks for the tip. I’m sure you have to say that hundreds of times a day!
Heh…unfortunately 'tis true. 
The first issue I see is with:
if enemyIndex < len(enemies):
Rather than using an ‘if’ statement, you should use a conditional loop instead. As written now, ‘enemyIndex’ will eventually become >= len(enemies), since you are incrementing it, so eventually, this entire ‘if’ block with be ignored.
Can you please help me with Clash of Clones? Here is my code:
while True:
enemy = hero.findNearestEnemy()
if enemy:
if hero.isReady("bash"):
hero.bash(enemy)
else:
hero.attack(enemy)
if hero.health <= 75:
hero.moveXY(41, 67)
break
is there an error or what? @TinyGoliath06
i suggest using not so good equipment to