Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Multiplayer Treasure Grove (Python) - Im a little stuck


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!

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

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:
elif item:
    get item


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