My hero won't summon anyone in Uneasy Truce


#1

Hello everyone,

This is my code. My hero doesn’t summon any soldiers.

function findSouthernUnits(units) {
    var southernUnits = [];
    for(var i=0; i < southernUnits.length; i++) {
        var unit = units[i];
        if(unit.pos.y < hero.pos.y) {
            // Add the unit to the array with: push()
            southernUnits.push(unit);
        }
    }
    return southernUnits;
}

while(true) {
    var friends = hero.findFriends();
    var enemies = hero.findEnemies();
    // Use findSouthernUnits to get enemies to the south.
var enemy = findSouthernUnits(enemies);
    // If there are more ogres south of you than friends.
    if (enemy.length > friends.length){
    
        // Then summon another "soldier".
        hero.summon("soldier");
}
}

#2

What are you doing here in function findSouthernUnits(units)?

for(var i=0; i < southernUnits.length; i++)

check the default code