[SOLVED] Zoo keeper help?

my code is supposed to get my hero to gather gold, summon soldiers, send them to some points and then they are supposed to defend a box. over all it works, but the issue is that they only go so far. they dont make it to their points i told them to go too. thank you in advance

1 Like

this is also in JavaScript

In order for us to help, you must format your code properly! you can do this by pressing the “</>” button or by typing in this formation
19%20AM

Make sure you read the topic properly before offering help. As you will be able to see if you look, this topic is solved, with the tick, and also has [SOLVED] in the title.
Thanks
Danny

Oopsy doopy daisy
sorry

1 Like

my hero is not collecting any coins, so I can’t summon any soldiers. here is my code.

// Protect the cage.
// Put a soldier at each X.
var points = [];
points[0] = {x: 33, y: 42};
points[1] = {x: 47, y: 42};
points[2] = {x: 33, y: 26};
points[3] = {x: 47, y: 26};

// 1. Collect 80 gold.
while(hero.gold >= 80) {
    while(true) {
       let item = hero.findNearestItem();
       if (item) {
            hero.moveXY(item.pos.x, item.pos.y);    
            }
    }
       }
// 2. Build 4 soldiers.
for (let i=0; i < 4; i++) {
    hero.summon("soldier");
}

// 3. Send your soldiers into position.
while(true) {
    var friends = hero.findFriends();
    for(var j=0; j < friends.length; j++) {
        var point = points[j];
        var friend = friends[j];
        var enemy = friend.findNearestEnemy();
        if(enemy && enemy.team == "ogres" && friend.distanceTo(enemy) < 5) {
            // Command friend to attack.
            hero.command(friend, "attack", enemy);
        } else {
            // Command friend to move to point.
            hero.command(friend, "move", point);
        }
    }
}

Figured it out! :grinning:

Changed ‘while(hero.gold >= 80)’ to ‘while(hero.gold < 80)’.