Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Gas Attack, Sarven Desert


My code doesn’t seem to work though it worked a while ago so I changed it a bunch but it still won’t work because I don’t know what variable to use.

def sumHealth(enemies):
    # Create a variable and set it to 0 to start the sum.
    totalHealth = 0
    # Initialize the loop index to 0
    index = 0
    # While index is less than the length of enemies array
    while index < len(enemies):
        # Add the current enemy's health to totalHealth
        totalHealth = enemies[index].value
        # Increment the index.
        index += 1

    return totalHealth

# Use the cannon to defeat the ogres.
cannon = hero.findNearest(hero.findFriends())
# The cannon can see through the walls.
enemies = cannon.findEnemies()
# Calculate the sum of the ogres' health.
ogreSummaryHealth = sumHealth(enemies)
hero.say("Use " + ogreSummaryHealth + " grams.")


Units are not coins (or gems). They don’t have value only health.


I did that and it worked but now only for one munchkin. I tried an infinite loop but it still did it only for one munchkin you would think it would do it for more.


Fixed the problem!


How? I still can’t do more than one!


health instead of value


Sorry, I found out.

cannon = hero.findNearest(hero.findFriends())
ogreSummaryHealth = 0
enemies = cannon.findEnemies()
ogreSummaryHealth = enemies[0].health + enemies[1].health + enemies[2].health + enemies[3].health +
enemies[4].health + enemies[5].health + enemies[6].health + enemies[7].health + enemies[8].health +
hero.say(“Use” + ogreSummaryHealth + “grams”)