Literally asking the same thing that everyone else is, what part of my code is causing my archers to move with the soldiers?
# Ogres are trying to take out your reindeer!
# Keep your archers back while summoning soldiers to attack.
# Collect coins.
item = hero.findNearestItem()
# Summon soldiers if you have the gold.
if hero.gold > hero.costOf("soldier"):
# This function has an argument named soldier.
# Arguments are like variables.
# The value of an argument is determined when the function is called.
# Soldiers should attack enemies.
enemy = hero.findNearestEnemy()
# Write a commandArcher function to tell your archers what to do!
# It should take one argument that will represent the archer passed to the function when it's called.
# Archers should only attack enemies who are closer than 25 meters, otherwise, stay still.
enemy = friend.findNearestEnemy()
distance = friend.distanceTo(enemy)
elif enemy and distance < 25:
hero.command(friend, "defend", "Reindeer")
friends = hero.findFriends()
for friend in friends:
if friend.type == "soldier":
# This friend will be assigned to the variable soldier in commandSoldier
elif friend.type == "archer":
# Be sure to command your archers.
you don’t need to defend the reindeer. Your troops don’t know what the reindeer are because you haven’t defined it. Tell it to attack because if the distance is too far, it wont attack. Other than that, it should be fine
yea but you will never get to the elif part because it will always say “Oh there’s an enemy. Lets find the distance! Let’s attack them!” instead of “Oh there’s an enemy. How far is it? Oh no, it’s farther than 25 meters. Let’s stay where we are.”