Uneasy truce/ Python/ Error/ help [SOLVED]

When i made the code it says that the line

    southernEnemies = []

Is undefined?
This is the full code

# Summon one soldier for every ogre to the south of you!
# Don't count the ogres to the north!

# Accept an array of units as the parameter.
# Return only the units to the south of the hero.
def FindSouthernEnemies(enemies):
    southernEnemies = []
    for enemy in enemies:
        if unit.pos.y < hero.pos.y:
            # Add the unit to the array with: append()
    return southernUnits

while True:
    friends = hero.findFriends()
    enemies = FindSouthernEnemies(enemies)
    # Use findSouthernUnits to get enemies to the south.
    # If there are more ogres south of you than friends.
    if len(enemies) > len(friends):
        # Then summon another "soldier".

Hi Some_Guy,

I think it’s just because ‘unit’ hasn’t been defined. You’re using ‘enemy’ in the the first half of the function, and then you try to add ‘unit’ to the array.


1 Like


unit = hero.findEnemies()

Replace the unit here with enemy, all three of them. Then you need to define enemies.

enemies = hero.findEnemies()

Once yu do that, you can use FindSouthernEnemies() with the parameter of enemies. Define a variable with this, but it has to be different than enemies or friends. If the length of that is greater than the length of friends, summon a soldier.

Thank you for the help

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.