Desert Combat: I am failing but why?

# while-loops repeat until the condition is false.

ordersGiven = 0
while ordersGiven < 5:
    # Move down 10 meters.
    hero.moveXY(hero.pos.x, hero.pos.y - 10)
    # Order your ally to "Attack!" with hero.say
    # They can only hear you if you are on the X.

    # Be sure to increment ordersGiven!

while True:
    enemy = hero.findNearestEnemy()
    # When you're done giving orders, join the attack.

This is my code and I don’t understand what happened. The point of this is to move down red Xes and say a message. On the 3rd X my player moves to the right. My code: hero.moveXY(hero.pos.x, hero.pos.y - 10). There is no change in my X so why does it move to the right?


hero.say(“ordersGiven”) don’t increment ordersGiven!


You need an if enemy after enemy = hero.findNearestEnemy. So

while True:
enemy = hero.findNearestEnemy

Would turn into

while True:
enemy = hero.findNearestEnemy
    if enemy:


the thing is the attack thing has nothing to do with the problem i have :frowning:


It says # Be sure to increment ordersGiven! I solved it and I didn't change my code at all I just tried it another day and it worked! Weird right.