Kith guard brawl 2 help


#1

Need help finding what is wrong with my code.


#2

Here it is loop:
enemy = self.findNearestEnemy()
if enemy:
hero.attack(enemy)
hero.attack(enemy)
hero.attack(enemy)
enemy = self.findNearestEnemy()
if enemy:
hero.attack(enemy)
hero.attack(enemy)
hero.attack(enemy)
items = hero.findItems()
for item in items:
hero.move()
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
hero.attack(enemy)
hero.attack(enemy)
hero.attack(enemy)
hero.attack(enemy)
items = hero.findItems()
for item in items:
hero.move()


#3

Please format your code according to the FAQ by selecting it and hitting the </> button on the menu above the box where you are writing.

You only need to find and attack the enemy a single time per loop:

while(True):
    enemy = self.findNearestEnemy()
    if enemy:
         hero.attack(enemy)

Writing hero.attack(enemy) more times doesn’t make you attack faster and if the enemy dies after the first attack your code will have problems.

Wait until you have beaten the forest world before you worry about picking up items. You will need to move to the item.pos.x and item.pos.y in order to do this.


#4

ok and the item moves constantly so how do i get it ??


#5

?? can anyone help me?


#6

I made a poster here that explains many things. One of them is how to pick up items. If moving to the item.pos.x and item.pos.y is not working you will need to use the hero.move(item.pos) This requires you to have boots with the move method, which are gained in the mountain world.


#7
        for item in items:
            hero.move()

Where do you move youre hero? The code right is:

   for item in items:
       hero.moveXY(item.pos.x,item.pos.y)

First. You need to place position. Second. move method move hero on one pixel.