# [SOLVED]Wild horses (python)

``````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)
``````
1 Like

Change that to:

``````horse = hero.findNearest(hero.findFriends())
``````
2 Likes

That should just be x1

That should be just x2.

2 Likes

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)

``````

You didn’t change it to:

``````horse = hero.findNearest(hero.findFriends())
``````

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.

lol got it. thank you, @abc

1 Like

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