Restless dead javascript

i not really recom flag because my pc can’t handle codecombat so it become so laggy i can’t even click
on a plce

hmm, then you should make a variable, set it to false, and then when you kill the yeti and collect the gems, you set it to true, if it is true, you move on, thats a way to do it with code

separate them to stages, thats what i mean, based on what you have done

1 Like

ok i continue tommorow i gtg

1 Like

maybe i should use the var pos = []; pos[1] = 'x: position.pos.x, ‘y’: position.pos.y
and use hero.command(friend, “defend”, pos);

and if hero.health < than hero health divide by 2
then he has to backup and let his friend protecting him
what do you think?

// This level is supposed to be VERY hard! You may need a great strategy and or gear to complete it!

// Find and defeat the yeti then gather its essence for the ritual.
// You might want to gather the coins the yeti leaves behind, you'll need them to summon an army
// Stand at the summoning stone (red x) to begin summoning
// Novar summonTyw you just have to survive the undead hoard
var summonTypes = ['soldier', 'archer'];
var pos = [];
pos[1] = {'x': 53, 'y': 48};
pos[2] = {'x': 48, 'y': 43};

function attack(enemy) {
    if (enemy) {
        while (enemy.health > 0) {
            if (hero.distanceTo(enemy) > 10) {
                hero.jumpTo(enemy.pos);
            }
            else if (hero.isReady("bash")) {
                hero.bash(enemy);
            }
            else if (hero.canCast("chain-lightning", enemy)) {
                hero.cast("chain-lightning", enemy);
            }
            else {
                hero.attack(enemy);
            }
        }
    }
}

function summon() {
    var types = summonTypes[hero.built.length % summonTypes.length];
    if (hero.gold > hero.costOf(types)) {
        hero.summon(types);
    }
}

function commandTroops() {
    var friends = hero.findFriends();
    for (var i = 0; i < friends.length; i++) {
        var friend = friends[i];
        if (friend.type == "soldier") {
            commandSoldier(friend);
        }
        else if (friend.type == "archer") {
            commandArcher(friend);
        }
    }
}

function commandArcher(archer) {
    var enemy = hero.findNearestEnemy();
    if (enemy && hero.distanceTo(enemy) < 14) {
        hero.command(archer, "attack", enemy);
    }
    else {
        hero.command(archer, "move", {'x': 49, 'y': 42});
    }
}

function commandSoldier(soldier) {
    var enemy = hero.findNearestEnemy();
    
    if (enemy) {
        hero.command(soldier, "attack", enemy);
    }
    else {
        hero.command(soldier, "defend", pos[0]);
    }
}

function range(start, end) {
    var ans = [];
    for (let i = start; i <= end; i++) {
        ans.push(i);
    }
    return ans;
}

function collect() {
    var item = hero.findNearestItem();
    while (item) {
        hero.move(item.pos);
        item = hero.findNearestItem();
    }
}


hero.moveXY(55, 10);
hero.wait(2);
attack(hero.findNearestEnemy());
collect();
hero.moveXY(55, 33);
hero.moveXY(49, 37);
hero.moveXY(19, 40);
for (var i in range(55, 48)) {
    summonTroops();
}
commandTroops();
hero.moveXY(55, 48);
if (hero.health < hero.maxHealth / 2.5) {
    hero.moveXY(33, 33);
}
while (true) {
    attack(hero.findNearestEnemy());
    commandTroops();
    collect();
}

here the code i put some of my ideas in here would you help me fix what this code wrong
hero not summon anything.

i take the range function in this website that show me how to use range in javascript

https://dev.to/ycmjason/how-to-create-range-in-javascript-539i

@Aya reply please need ur help

1 Like

Sorry, was busy earlier

You have the function of summoning troops defined differently than when you called it

1 Like

oohhhh i confuse that thanks wait it doesn’t mean it solved yet

1 Like

here the code still doesn’t summon

// This level is supposed to be VERY hard! You may need a great strategy and or gear to complete it!

// Find and defeat the yeti then gather its essence for the ritual.
// You might want to gather the coins the yeti leaves behind, you'll need them to summon an army
// Stand at the summoning stone (red x) to begin summoning
// Novar summonTyw you just have to survive the undead hoard
var summonTypes = ['soldier', 'archer'];
var pos = [];
pos[1] = {'x': 53, 'y': 48};
pos[2] = {'x': 48, 'y': 43};

function attack(enemy) {
    if (enemy) {
        while (enemy.health > 0) {
            if (hero.distanceTo(enemy) > 10) {
                hero.jumpTo(enemy.pos);
            }
            else if (hero.isReady("bash")) {
                hero.bash(enemy);
            }
            else if (hero.canCast("chain-lightning", enemy)) {
                hero.cast("chain-lightning", enemy);
            }
            else {
                hero.attack(enemy);
            }
        }
    }
}

function summonTroops() {
    var types = summonTypes[hero.built.length % summonTypes.length];
    if (hero.gold > hero.costOf(types)) {
        hero.summon(types);
    }
}

function commandTroops() {
    var friends = hero.findFriends();
    for (var i = 0; i < friends.length; i++) {
        var friend = friends[i];
        if (friend.type == "soldier") {
            commandSoldier(friend);
        }
        else if (friend.type == "archer") {
            commandArcher(friend);
        }
    }
}

function commandArcher(archer) {
    var enemy = hero.findNearestEnemy();
    if (enemy && hero.distanceTo(enemy) < 14) {
        hero.command(archer, "attack", enemy);
    }
    else {
        hero.command(archer, "move", {'x': 49, 'y': 42});
    }
}

function commandSoldier(soldier) {
    var enemy = hero.findNearestEnemy();
    
    if (enemy) {
        hero.command(soldier, "attack", enemy);
    }
    else {
        hero.command(soldier, "defend", pos[0]);
    }
}

function range(start, end) {
    var ans = [];
    for (let i = start; i <= end; i++) {
        ans.push(i);
    }
    return ans;
}

function collect() {
    var item = hero.findNearestItem();
    while (item) {
        hero.move(item.pos);
        item = hero.findNearestItem();
    }
}


hero.moveXY(55, 10);
hero.wait(2);
attack(hero.findNearestEnemy());
collect();
hero.moveXY(55, 33);
hero.moveXY(49, 37);
hero.moveXY(19, 40);
for (var i in range(55, 48)) {
    summonTroops();
}
commandTroops();
hero.moveXY(55, 48);
if (hero.health < hero.maxHealth / 2.5) {
    hero.moveXY(33, 33);
}
while (true) {
    attack(hero.findNearestEnemy());
    commandTroops();
    collect();
}

they weak compared too the enemy

I’ll recheck the code once I’m free

1 Like

I’m not sure if making all of this for picking a type is necessary. I think pick either soldiers or archers, or you can make a for-loop for soldiers and another for archers

Also, why is this here?

i think it is unnecessary

how do i get range in javascript?

I dont think there is, why do you need it tho?

this look at this 20 char

i think this is the problem why hero not summoning

Probably that (20chars)

i think the main problem is the range part it not working

1 Like