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

Uneasy Truce Python


#1

It’s showing me this strange error.
Here my code

def findSouthernUnits(units):
    southernUnits = []
    for unit in units:
        if unit.pos.y < hero.pos.y:
            # Add the unit to the array with: append()
            southernUnits.append(unit)
    return southernUnits


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

and the capture of the error


#2

see additional comments:

while True:
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    # Use findSouthernUnits to get enemies to the south.
    findSouthernUnits() # enemies to the south have to be put on a new array variable
                        # southernUnits = findSouthernUnits(units)
                        # where units are the enemies from hero.findEnemies()
    # If there are more ogres south of you than friends.
    if southernUnits > friends: # you compare two arrays and they're both objects 
                                # instead you must compare their length
                                # if len(array1) > len(array2) 
        # Then summon another "soldier".
        hero.summon("soldier")

As side note:
In code combat python implementation

if array1.length > array2.length: # is equal to
if len(array1) > len(array2): 

Learnt it just now :slight_smile:


#3

Still don’t understand ;(
Truc

def findSouthernUnits(units):
    southernUnits = []
    for unit in units:
        if unit.pos.y < hero.pos.y:
            # Add the unit to the array with: append()
            southernUnits.append(unit)
    return southernUnits


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

#4

Hi,
The error is in this line:

What if there wasn’t a unit?
:lion: :lion: :lion: