I don’t know what’s wrong with my code. 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]);
}
}
}