It’s my last level in the forest!! but I can’t get my code right. please help!!
while True:
# How do you find the nearest friendly unit?
# horse = ?
horse = hero.findByType("horse", hero.findFriends())[0]
if horse:
x1 = horse.pos.x - 7
x2 = horse.pos.x + 7
if x1 >= 1:
# Move to the horse's y position but use x1 for the x position.
hero.moveXY(horse.pos.x1, horse.pos.y)
elif x2 <= 79:
# Move to the horse's y position but use x2 for the x position.
hero.moveXY(horse.pos.x2, horse.pos.y)
distance = hero.distanceTo(horse)
if distance <= 10:
hero.say("Whoa")
# Move to the red x to return the horse to the farm.
hero.moveXY(27, 54)
# Move back out into the pasture to begin looking for the next horse.
hero.moveXY(45, 31)
Thanks, I did that. but my hero’s still doing nothing.
while True:
# How do you find the nearest friendly unit?
# horse = ?
horse = hero.findNearest("horse", hero.findFriends())
if horse:
x1 = horse.pos.x - 7
x2 = horse.pos.x + 7
if x1 >= 1:
# Move to the horse's y position but use x1 for the x position.
hero.moveXY(x1, horse.pos.y)
elif x2 <= 79:
# Move to the horse's y position but use x2 for the x position.
hero.moveXY(x2, horse.pos.y)
distance = hero.distanceTo(horse)
if distance <= 10:
hero.say("Whoa")
# Move to the red x to return the horse to the farm.
hero.moveXY(27, 54)
# Move back out into the pasture to begin looking for the next horse.
hero.moveXY(45, 31)
A horse is allied on team humans, so it is your friend. You need to find the nearest friend, so you use the hero.findFriends() method within the hero.findNearest() method to find the nearest friend.