Summit's Gate. Again. Errors =]

Hi. I got this error


it’s say that I choose wrong unit.

but I select friends and give it to function

 var friends = hero.findFriends();
    
 for (var j = 0; j < friends.length; j++) {
        if (friends[j].type == "soldier") {
            soldiers(friends[j]);
        }}

look like “warlock” cast some spell on my soldiers to fight against me and it crash my code. How to fix it? How to check friend state if he still a friend?

You think it may be a bug?

maybe I need something like

if(friend.hasEffect === false){
     command();
}

also this level is really glithcy, it take all my RAM memory and I can not work with flags.

Ok…you may need @nick or @ChronistGilver

new problems

  1. all RAM used

  1. my troops don’t follow me after doors is fallen

this is code for soldiers and archers

I separate them into 2 functions, nothing superHard


function archersCommand(archers) {
    for (var i = 0; i < archers.length; i++) {
        var enemy = archers[i].findNearestEnemy();
        var enemy2 = hero.findNearestEnemy();
        if (enemy) {
            hero.command(archers[i], "attack", enemy);
        } else {
            hero.command(archers[i], "defend", hero.pos);
        }
    }
}
function soldiersCommand(soldiers) {
    for (var i = 0; i < soldiers.length; i++) {
        var enemy = soldiers[i].findNearestEnemy();
        var enemy2 = hero.findNearestEnemy();
        if (enemy) {
            hero.command(soldiers[i], "attack", enemy);
        } else {
            hero.command(soldiers[i], "defend", hero.pos);
        }
    }
}

and call them into while loop

while (true) {
    startOfStage(stage);
    attackStage(superunits[stage]);
    paladinHealing(hero.findByType("paladin"));
    soldiersCommand(hero.findByType("soldier"));
    archersCommand(hero.findByType("archer"));
    cleaningStage();
    endStage();
}

I place this fucntion on top of the list, now they attack.

while (true) {

    soldiersCommand(hero.findByType("soldier"));
    archersCommand(hero.findByType("archer"));
    startOfStage(stage);
    attackStage(superunits[stage]);
    paladinHealing(hero.findByType("paladin"));
    cleaningStage();
    endStage();
}

This level crashes Chrome browser a few times because 4 GB memory is no enough to run CodeCombat
and thanx for not much help

painfully

Victory.

it was hard not about coding but about lags

FPS = pain in the butt

You need someone to help?

no. coz I have VICTORY already. but freaking FPS !

I have 200 lines of code, and after each editing this was real pain to test the level


#I pass this level with 20 lines of code(python), and my computer has only 3G RAM.

1 Like

20 lines is awesome, man