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

Rich Forager using Python[SOLVED]

Hello, I have been stuck on this level for a few days now… I was wondering if you could point out any mistakes that would help me?

while True:
    flag = self.findFlag()
    enemy = self.findNearestEnemy()
    item = self.findNearestItem()

if flag:
elif enemy:
    if self.isReady("cleave"):
    if item:
        itemPOS = item.pos
        itemx = itempos.x
        itemy = itempos.y
        self.moveXY(itemX, itemY)

1 Like

Hey there, welcome to the CodeCombat discourse!
With your indentation of the if-statement block, you’ll only check for and move to items, while there is an enemy!
Preferable change it to elif and move it further left, out of the elif enemy block. in addition to that, you have declared (not sure if that’s important for python) the item variables once with split uppercase/lowercase and then used it differently after that.
Hope it helped :sweat_smile:
If there are further issues (or not-solved ones with what i think was a potential problem), please let us know more about the issue you’re having!

Also: increase the spacing on the left for every line after
item = self.findNearestItem()
If i’m correct, it’s probably not running because it isn’t considered in the while True: loop.


Thank you so much bro! :upside_down_face:

1 Like