Desert Combat stuck

ordersGiven = 0
enemy = self.findNearestEnemy()
while ordersGiven < 5:
    self.say("Attack!")
    x = self.pos.x
    y = self.pos.y - 10
    self.moveXY(x, y)
    ordersGiven = ordersGiven+1.
while ordersGiven>=5:
    self.moveXY(51, 32)
    self.attack(enemy)

How do I attack that the Enemy?

OK, I added the ``` on separate lines before and after your code (Please do so yourself in the future, it makes it easier to read with the indents and python is picky about them. so they need to be seen.)

If I remember right, there is a barricade between you and the big brawler. Looking at your code I’d say you walk to a spot then attack something, then walk to the spot, then attack something, then…

So???

AH, I see it . . . it is the tricky attack one and only one enemy problem.

The barricade is an “enemy”, so once it is destroyed your hero has no enemy to attack any more.
You need to set “enemy = …” inside your attack loop. (So your hero can get updated info.)

vlevo is right:
u define :

enemy = self.findNearestEnemy()

the fence is now your enemy. in your second while loop you attack this enemy until its dead. but u do not look for new enemies. Your code should always check for new enemies, so it should be inside the while loop, like the self.attack.

1 Like

thanks guys you guys rock. :smile:

1 Like