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

[SOVED] Help with The Two Flowers


So, some of my soldiers will attack, some will just stand there, my hero just runs around collecting coins, and Hector always dies.

// If the peasant is damaged, the flowers will shrink!

function summonSoldiers() {
    if ( >= hero.costOf("soldier")) {

// Define the function: commandSoldiers
function commandSoldiers() {
    var soldiers = hero.findByType("soldier", hero.findFriends());
    var soldierIndex =0;
    for(var i =0; i< soldiers.length; i++){
        var soldier = soldiers[soldierIndex];
        var enemy = soldier.findNearestEnemy();
       hero.command(soldier, 'attack', enemy);

// Define the function: pickUpNearestCoin
function pickUpNearestCoin(){
    var coin = hero.findNearestItem();
    if (coin){
var peasant = hero.findByType("peasant")[0];

while(true) {
    // commandSoldiers();
    // pickUpNearestCoin();


1.You do not have to define soldierIndex you have i that is the same thing.
So it should be var soldier = soldiers[i];and you should delete var soldierIndex =0; you define index inside for loop.


yay that worked! you rock <3