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?
Luke10
February 14, 2017, 1:36pm
3
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.
Luke10
February 14, 2017, 10:10pm
5
Ok…you may need @nick or @ChronistGilver
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
Luke10
February 15, 2017, 4:57pm
11
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
jack225
February 16, 2017, 12:50am
13
#I pass this level with 20 lines of code(python), and my computer has only 3G RAM.
1 Like