[SOLVED] Need help with "Wild Horses"

I need help with “Wild Horses”
This is what I have:

(while True:
# How do you find the nearest friendly unit?
# horse = ?
horse = hero.findNearestFriend()
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, harse.pos.y)
    distance = hero.distanceTo(horse)
    if distance <= 10:
        # 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(64, 31)

Welcome‌ ‌welcome‌ ‌to‌ ‌the‌ ‌forum!‌ ‌It‌ ‌is‌ ‌a‌ ‌lovely‌ ‌place‌ ‌where‌ ‌you‌ ‌can‌ ‌share‌ ‌all‌ ‌kinds‌ ‌of‌ stuff‌ ‌(appropriate‌ ‌of‌ ‌course),‌ ‌share‌ ‌bugs,‌ ‌and‌ ‌even‌ ‌get‌ ‌assistance‌ ‌for‌ ‌code!‌ ‌We‌ ‌suggest‌ ‌that‌ ‌you‌ ‌review‌ ‌this‌‌ topic‌ ‌which‌ ‌shows‌ ‌all‌ ‌essentials‌ ‌of‌ ‌this‌ ‌board!‌ ‌And‌ ‌we‌ ‌suggest‌ ‌you‌ ‌review‌ this topic‌ ‌which‌ ‌shows‌ ‌how‌ ‌to‌ ‌post‌ ‌your‌ ‌code‌ ‌correctly!‌ ‌Thanks!!‌ ‌ :partying_face: :partying_face:
Please format your code correctly and can you send a link to the level?

@Lydia_Song, here’s the level link: CodeCombat - Coding games to learn Python and JavaScript?


Welcome to the CoCo(CodeCombat) Discourse, @coeding3. :partying_face:

You spelt “horse” wrong, here(line 14):

Also, could you send a screenshot of your equipment?


Yes, you have misspelled the word horse, so you won’t be able to move. Next, hero.findNearestFriend() is not a method for your hero. You need to find the nearest unit with hero.findNearest(). You need to find the nearest unit of friends. To do that, you could find friends and define a variable called friends, then use friends, like this: hero.findNearest(friends). Or you can just find friends within it like this: hero.findNearest(hero.findFriends()).

Yes. Here it is:

1 Like

Done! I did it. It was helpful.

1 Like

Congrats on solving the level @coeding3.

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