Please help on level Sarven Desert - Fair Battle

Hi and thanks for reading this :slight_smile:

I’ve been stuck in this level, somehow the total health of soldier is greater than ogres at the begining and I couldn’t even kill one ogre… if it’s something wrong with my code, could someone help me please? Many thank:sweat:

def sumHealth(units):
    totalHealth = 0
    unitsIndex = 0
    
    while unitsIndex < len(units):
        unit = units[unitsIndex]
        if unit.health > totalHealth:
            totalHealth += unit.health
        
        unitsIndex += 1
        
        return totalHealth

while True:
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    # Get the total health of your soldiers and the ogres.
    soldierHealth = sumHealth(friends)
    ogreHealth = sumHealth(enemies)
    # Say "Attack" when your side has more total health.
    if soldierHealth != ogreHealth:
        if soldierHealth > ogreHealth:
            hero.say("Attack")
    pass

don’t post the same post in 2 places please. (Especially since you only waited 43 minutes between your posts)

Hi SuperSmacker, sorry for the additional post
:sweat_smile:

is that python or javascript?

Welcome to the forums @gnarlyMarley :partying_face: :partying_face:
This is a family friendly place where you can talk about coding, and other things.
Please don’t necropost, this topic is 5 years old :slightly_smiling_face:
And, these users are not active anymore.