Timber Turncoat - Help - Javascript

My code works but soldiers aren’t strong enough

function collect() {
    let item = hero.findNearestItem();
    let coin = item.pos;
    if (hero.gold < 25 && item.value > 2) {
        hero.moveXY(coin.x, coin.y);
         
    }
    else if (hero.gold < 25 && item.value > 1) {
        hero.moveXY(coin.x, coin.y);
    }
    else{
        
        hero.moveXY(coin.x, coin.y);
    }
        
    if (hero.gold > 40) {
        hero.summon("soldier");
                hero.summon("soldier");

      
    }
}
function command() {
    let friends = hero.findFriends();
    let enemy = hero.findNearestEnemy();
    for (let i = 0; i < friends.length; i++) {
        let friend = friends[i];
        if (friend.type == "soldier" && enemy) {
            hero.command(friend, "attack", enemy);
        } else if (friend.type == "soldier" && !enemy) {
            hero.command(friend, "move", {
                "x": 85,
                "y": 45
            });
            continue;
            
        }  if (friend.type == "soldier" && friend.health < 100) {
            hero.command(friend, "move", {
                "x": 17,
                "y": 46
            });
        }
    }
}
while (true) {
    collect();
    command();
}

edit:
it worked after restarting the browser…

my original code had only

if (hero.gold < 25 ) {
        hero.moveXY(coin.x, coin.y);

without other the other ones that you will see on the first post (like value >1 etc);

but after restarting the browser, they all work

Welcome to the discourse @k2adir1! I hope you enjoy your time here.

if you are finished with the level please click the checkbox next to one of the replies on this topic to close it thanks.

1 Like

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