Desert Combat stuck


#1
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?


#2

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.)


#3

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.


#4

thanks guys you guys rock. :smile: