Wild Horses-Python


#1

The other topics don’t seem to help me. Please Help!!! :expressionless:


#2

loop:
# How do you find the nearest friendly unit?
horse = self.findFriends()
if horse:
x1 = horse.pos.x - 7
x2 = horse.pos.x + 7

    if x1 >= 1:
        self.moveXY(x1, horse.pos.y)
        # Move to the horse's y position but use x1 for the x position.
        
    elif x2 <= 79:
        # Move to the horse's y position but use x2 for the x position.
        
    distance = self.distanceTo(horse)
    if distance <= 10:
        self.say("Whoa")
        self.moveXY(27, 54)
        self.moveXY(43, 21)
        # Move to the red x to return the horse to the farm.
        
        # Move back out into the pasture to begin looking for the next horse.

(This is my code)


#3

what do you need help with?


#4

It always says: unable to get property x, and then once I solve that, I don’t know what to do next…


#5

Well, you never told it what to do when x2 <= 79.


#6

oh… ok, i get it. Let me try it right now.


#7

I will work if it is exactly right there are no guarantees :stuck_out_tongue:


#8

Yeah…I’m going to skip this for now.


#9

When you use self.findFriends(), the program found all of the friends and put them in an array. You just want one horse. I would suggest the nearest horse. Assign the nearest friend to the horse variable and then can use the rest of the code to go stand near the horse, tell it , “Whoa,” and lead to the the gate.