Multiplayer Treasure Grove (Python) - Im a little stuck


#1

I have been successfully able to have my character move around the screen but have not been able to automate the attacks on the CPU character. I would really appreciate it if someone could give me some feedback on my code!

loop:
    item = self.findNearestItem()
    if item:
        pos = item.pos
        x = pos.x
        y = pos.y
        self.moveXY(x, y)
        continue
    enemy = self.findNearestEnemy()
    elif self.distanceTo(enemy) < 10:
        if self.isReady("cleave"):
            self.cleave(enemy)
            continue
        else:
            self.attack(enemy)

#2

Your problem is with your if and elif You will only attack the enemy if there is no item. That doesn’t happen in treasure grove. Switch them.

if enemy and distanceTo(enemy) < 10:
    self.attack(enemy)
elif item:
    get item



#3

Thanks so much! I was able to fix the code and have the intended outcome:)
Now to work through more levels and figure out how to work the coin value into my code so I can optimize the collection process:)