Level Toil and Trouble


#1

can anyone help me by this level?

here is my code:

this.chooseTarget = function(friend) {
    if (friend == "soldier") {
        return this.findByType("witch");
    }
    else {
        return this.findEnemies(); 
    }
};    
loop {
    var friends = this.findFriends();
    for(i=0; i < friends.length; i++) {            
        var friend = friends[i];
        var enemy =  friend.findNearest(this.chooseTarget(friend.type));
        if (enemy) {
            this.command(friend, "attack", enemy);
        }       
    }
}

#2

Try friend.type instead of “friend” in line 2.


#3

the Qode works
but i dont win the level


#4

Should work with that change; what ends up happening?


#5

at the end not all ogres die
I dont have an idea what I can do
please help me


#6

Your guys die before killing them? Do the soldiers go straight for the witches, while the archers shoot the nearest ogres to themselves? Or do the soldiers attack the nearest ogres, too?

Remember you have to make the change GundericusTheMighty suggested.


#7

yes my guys die before
the soldiers attack only the witches and the archers attack the nearest orgres


#8

What are the archers attacking? They should be going after the throwers first.


#9

Depending on what glasses you have equipped for some reason you can’t always see the bottom throwers. Your friends can, so you could replace this.findEnemies() with friend.findEnemies().


#10

thank you very much trotod
now it works :smile: