Help with mad maxer strikes back


#1

a little help?

while True:
    weakest = None
    leastHealth = 99999
    enemyIndex = 0
    enemies = hero.findEnemies()
    # Loop through all enemies.
    while enemyIndex < enemies:
        # If an enemy's health is less than leastHealth,
        if enemy.health < leastHealth:
            # make it the weakest and set leastHealth to its health.
            enemy = weakest
            enemy.health = leastHealth
            enemyIndex += 1
    if weakest:
        # Attack the weakest ogre.
        hero.attack(weakest)
        pass

#2

you need to define enemy. You never define enemy before the if statement. Also, in the if statement you define enemy as weakest. You need to define weakest as enemy, not the other way around.


#3

Help please, my hero just stands there when I run it.

while True:
    weakest = None
    leastHealth = 99999
    enemyIndex = 0
    enemies = hero.findEnemies()
    enemy = enemies[enemyIndex]
    # Loop through all enemies.
    while enemyIndex < enemies:
        # If an enemy's health is less than leastHealth,
        if enemy.health < leastHealth:
            # make it the weakest and set leastHealth to its health.
            weakest = enemy
            enemy.health = leastHealth
            enemyIndex += 1
    if weakest:
        # Attack the weakest ogre.
        hero.attack(weakest)
        pass


#4

There are three problems with your code.

  1. The while conditional statement does not address the array (length) of enemies.
  2. leastHealth should not be assigned to enemy.health (it should be the other way around).
  3. The last is a structure issue; enemyIndex += 1 is not tabbed correctly.

`


#5

Thank you, it worked!