Dance-Off help? Look at my code please

while True:
    friend = hero.findNearest(hero.findFriends())
    if friend:
        hero.moveXY(friend.pos.x, friend.pos.y - 6)

What’s wrong with my solution?
Everything looks ok when executed, except at the last part when they are lined up in a straight line. One other “friend” who is not my dance partner takes my spot in line behind my dance partner and my hero is forced to the end of the line.

Not sure if that’s why it’s not completing, and if so how to solve it?

Everything looks ok until that point at the end. I don’t know what else could be wrong. Please help. Thank you!


findFriends returns an array. Either use a for loop to loop through the array or just this to find the nearest friend:

    friend = hero.findNearest(hero.findFriends()[0])


Thanks for the assist.

I was able to solve this without using a For loop or [0] added to the original code.
I also found a second solution with a For loop.

The main thing that I was missing in both solutions was the use of the DistanceTo method.