[SOLVED]Trouble with code - summits gate

Hi!

I made the beginning of the code to see something, but…I wonder why one paladin is moving, but soldiers are not! Whaaaat is wrong? D:

Here is my code:

function phase1UnitCommand(friends) {
    var soldiers = [];
    var archers = [];
    var paladins = [];
    for (var friendIndex = 0; friendIndex < friends.length; friendIndex++) {
        var friend = friends[friendIndex];
        if (friend.type == "soldier") {
            soldiers.push(friend);
        }
        if (friend.type == "archer") {
            archers.push(friend);
        }
        if (friend.type == "paladin") {
            paladins.push(friend);
        }
    }
    
    for(var soldierIndex = 0; soldierIndex < soldiers.length; soldierIndex++) {
        var soldier = soldiers[soldierIndex];
        var catapults = hero.findByType("catapult");
        if (catapults && soldierIndex / 2 === 0) {
            hero.command(friend, "attack", catapults[0]);
        }
        else if (catapults) {
            hero.command(friend, "attack", catapults[1]);
        }
    }
}
var friends = hero.findFriends();
phase1UnitCommand(friends);

Can somebody tell me what is wrong with it? I just wanted my soldiers to attack catapults. NOT THE PALADIN >_>

Hi, I think it might be because you haven’t commanded the paladins at all. Meaning they will follow their automatic strategy to attack the enemy. Would that make sense in your situation?
Danny

Thanks for hint, but I thought that I commanded soldiers and gave them orders to attack. I created 3 arrays and assigned soldiers in “soldiers” array, so I thought that soldiers will come and attack

for(var soldierIndex = 0; soldierIndex < soldiers.length; soldierIndex++) {
        var soldier = soldiers[soldierIndex];
        var catapults = hero.findByType("catapult");
        if (catapults && soldierIndex / 2 === 0) {
            hero.command(friend, "attack", catapults[0]);
        }
        else if (catapults) {
            hero.command(soldier, "attack", catapults[1]);
        }
    }

, but paladins came out instead. That is my problem.

Oh, now I see. I have “command friend” instead of “command soldiers”. I fixed it, but still one paladin is coming among soldiers. Still I don’t want him to go, because this is soldiers only array :smiley:

Ah, yes.
Could you post a screenshot of this along with your new code.
Thanks
Danny

Nevermind. I rebooted website and everything is working right now. Thanks again :smiley: