[SOLVED]Help hunting party, javascript

// You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
while (true) {
    var friends = hero.findFriends();
    // Use for-loop and for each friend:
    for (var friend in friends) {
        // If they see an enemy then command to attack.
        var enemy = friend.findNearestEnemy();
        if (enemy) {
            hero.command(friend, "attack", enemy);
        // Command to move east by small steps.
        else {
            hero.command(friend, "move", {'x': friend.pos.x + 1, 'y': friend.pos.y});

@milton.jinich or @Falcons118 help?

1 Like

sure just give me a sec

says friend doesn’t have method “findNearestEnemy();”

1 Like

What is the problem or error?

@Dragonlouis change your for loop to this and your code works for me

for (var i=0; i<friends.length;i++) {
        var friend=friends[i];

@Dragonlouis your code works just change that one little part and it should run
from this

  for (var friend in friends) {

to this

edit: if any of these work please mark any post that helped as solved so that this topic will be closed
Thanks :grin:

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