# Fair Battle/ Python/ Help [Solved]

My person either isn’t defining the health or is choosing not to say it

``````while True:
friends = hero.findFriends()
enemies = hero.findEnemies()
# Calculate and compare the total health of your soldiers and the ogres.
def healthSum(enemies):
enemiesIndex = 0
health = 0
while enemiesIndex < enemies.len:
enemies = enemies[enemiesIndex]
enemiesIndex +=1
health += enemies.health
return health

def healthSum(friends):
friendsIndex = 0
health = 0
while friendsIndex < friends.len:
friends = friends[friendsIndex]
friendsIndex +=1
health += friends.health
return health

if healthSum(friends) > healthSum(enemies):
hero.say("Attack")
# Say "Attack" when you are ready.
``````

Which sense stone do you have? i used quartz and later the sapphire one.

name the functions differently please, thats all that is wrong

That doesn’t matter.

does, healthSum doesnt know which one you are talking about, and the thing in the brackets has no value, its just an internal variable.
use:

``````while True:
friends = hero.findFriends()
enemies = hero.findEnemies()
# Calculate and compare the total health of your soldiers and the ogres.
enemiesIndex = 0
health = 0
while enemiesIndex < enemies.len:
enemies = enemies[enemiesIndex]
enemiesIndex +=1
health += enemies.health
return health

def healthSumGood(friends):
friendsIndex = 0
health = 0
while friendsIndex < friends.len:
friends = friends[friendsIndex]
friendsIndex +=1
health += friends.health
return health

hero.say("Attack")
# Say "Attack" when you are ready.
``````

i’ve fixed it, ill edit it out if its a working piece of code

Like this? Its still not working

``````while True:
friends = hero.findFriends()
enemies = hero.findEnemies()
# Calculate and compare the total health of your soldiers and the ogres.
def healthSumEnemy(enemies):
enemiesIndex = 0
health = 0
while enemiesIndex < enemies.len:
enemies = enemies[enemiesIndex]
enemiesIndex +=1
health += enemies.health
return health

def healthSumFreind(friends):
friendsIndex = 0
health = 0
while friendsIndex < friends.len:
friends = friends[friendsIndex]
friendsIndex +=1
health += friends.health
return health

if healthSumFreind(friends) > healthSumEnemy(enemies):
hero.say("Attack")
# Say "Attack" when you are ready.
``````

Yeah basically, mabye @Rachel699 could help, or another experienced player
(i’m a veteran but im still on cloudrip and i suck)

1 Like

maybe put this in a loop

Do you mean in a different while loop or the same on the rest is

so just put that in this `while True:`

so like this?

``````while True:
friends = hero.findFriends()
enemies = hero.findEnemies()
# Calculate and compare the total health of your soldiers and the ogres.
def healthSumEnemy(enemies):
enemiesIndex = 0
health = 0
while enemiesIndex < enemies.len:
enemies = enemies[enemiesIndex]
enemiesIndex +=1
health += enemies.health
return health

def healthSumFreind(friends):
friendsIndex = 0
health = 0
while friendsIndex < friends.len:
friends = friends[friendsIndex]
friendsIndex +=1
health += friends.health
return health

if healthSumFreind(friends) > healthSumEnemy(enemies):
hero.say("Attack")
``````

its still not working

No just this part, thats all.

So like this? @milton.jinich

``````def healthSumEnemy(enemies):
enemiesIndex = 0
health = 0
while enemiesIndex < enemies.len:
enemies = enemies[enemiesIndex]
enemiesIndex +=1
health += enemies.health
return health

def healthSumFreind(friends):
friendsIndex = 0
health = 0
while friendsIndex < friends.len:
friends = friends[friendsIndex]
friendsIndex +=1
health += friends.health
return health
while True:
if healthSumFreind(friends) > healthSumEnemy(enemies):
hero.say("Attack")
# Say "Attack" when you are ready.
``````

Its still not working

It looks like you are not attacking look here

There is nothing below it so how do you plan to attack?

Look above `# Say "Attack" when you are ready.`

Can I please have a link to the level? and your stuff to so I can see what abilities you have are you a sub?

You need to write the code like this:

``````enemy = enemies[enemiesIndex]
enemiesIndex += 1
health += enemy.health
``````

It is just that you have 2 enemies lists/variable, and the code doesn’t know which one you are talking about. Do that to the friends function and you should be good. Hope this helps,
Lukas

2 Likes

``````def healthSumEnemy(enemies):
enemiesIndex = 0
health = 0
while enemiesIndex < enemies.len:
enemies = enemies[enemiesIndex]
enemiesIndex +=1
health += enemies.health
return health

def healthSumFriend(friends):
friendsIndex = 0
health = 0
while friendsIndex < friends.len:
friends = friends[friendsIndex]
friendsIndex +=1
health += friends.health
return health
while True:
if healthSumFriend(friends) > healthSumEnemy(enemies):
hero.say("Attack")
``````

Like this?

``````def healthSumEnemy(enemies):
enemiesIndex = 0
health = 0
while enemiesIndex < enemies.len:
enemy = enemies[enemiesIndex]
enemiesIndex +=1
health += enemy.health
return health

``````