Protect And Serve help! please!

I don’t know what’s wrong with my code. :sob: this is what it looks like

// Protect the workers and animals!

// Defend these two positions:
let defend = [];
defend[0] = {x: 98,y: 28};
defend[1] = {x: 84,y: 7};
let soldiers = [];
let friends = hero.findFriends();
for (let i = 0; i < friends.length; i++) {
   let friend = friends[i];
   if (friend.type == "soldier") {
       soldiers.push(friend);
   } else {
// Defend the workers:
       defend.push(friend);
   }
}
while (true) {
   // Use a for-loop to assign each soldier to a corresponding defend[] target
   // Use command(soldier, "defend", thang) or command(soldier, "defend", position)
   for (let friend of friends) {
if (friend.type == "soldier" || friend.type == "archer") {
hero.command(friend, "defend", defend[1]);
       }
   }
}

(deleted - I forgot that indentation doesn’t matter in JS)

I don’t know what indentation means. :face_with_raised_eyebrow:

I’m sorry I can’t help. I only know python :frowning_face:

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