Help on CloudTrip Commander CS4 Javascript

I typed in the code correctly but only one soldier is moving. Please help here is the code


// Summon some soldiers, then direct them to your base.

// Each soldier costs 20 gold.
while (hero.gold > hero.costOf("soldier")) {
    hero.summon("soldier");
}
    
var soldiers = hero.findFriends();
var soldierIndex = 0;
// Add a while loop to command all the soldiers.
while(true){
    var soldier = soldiers[soldierIndex];
    hero.command(soldier, "move", {x: 50, y: 40});
}
// Go join your comrades!
var enemy = hero.findNearestEnemy();
if(enemy){
    while(true){
        var enemy = hero.findNearestEnemy();
        hero.attack(enemy);
    }
}

Yall are no help i fixed it here’s the code.


// Summon some soldiers, then direct them to your base.

// Each soldier costs 20 gold.
while (hero.gold > hero.costOf("soldier")) {
    hero.summon("soldier");
}
    
var soldiers = hero.findFriends();
var soldierIndex = 0;
// Add a while loop to command all the soldiers.
while(true){
    var soldier = soldiers[soldierIndex];
    var soldier0 = soldiers[4];
    var soldier1 = soldiers[1];
    var soldier2 = soldiers[2];
    var soldier3 = soldiers[3];
    hero.command(soldier, "move", {x: 50, y: 40});
    hero.command(soldier1, "move", {x: 50, y: 40});
    hero.command(soldier2, "move", {x: 50, y: 40});
    hero.command(soldier3, "move", {x: 50, y: 40});
    hero.command(soldier0, "move", {x: 50, y: 40});
    break;
}
// Go join your comrades!
hero.moveXY(50, 40);

Welcome to the discourse @27narellano might take a few hours or a day, but someone will help you, just be patient. And please don’t post solutions, other coders might copy it and get free answers without learning from it.

Ok quandale dingle, bud only responded when i posted the code.
:nerd_face: :nerd_face: :nerd_face:

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