Cursed Valley! My character is not picking up the potion!


#1

Hey CodeCombat supporters! I’m struggling with the cursed valley, and in general Sarven Desert :frowning:

The other levels leading up to this were manageable, but I feel like it’s a lot harder now. I think I’m really struggling with the idea or concept of arrays. If anyone has a cool analogy, I’d love to hear it.

Your help and insight would be appreciated, my guy doesn’t pick up the potion :frowning:

while True:
    item = hero.findNearestItem()
    # Take only the items with a "potion" type AND only when your health is less than a quarter of the maxHealth.
    if item and hero.health < max.health/4 and item.type == "potion":
        hero.moveXY(item.pos.x, item.pos.y)

#2

hero.health < max.health/4

hero.health < hero.maxHealth / 4


#3

thanks :smile:

so many clumsy mistakes… when will it end haha


#4

I was having the same problem with this level as well. I ended up changing it to Emm_S’s code and it worked but I’m still wondering about my code.
item = hero.findNearestItem()
if item and item.type == “potion” and hero.health < hero.maxHealth / 4:
hero.moveXY(item.pos.x, item.pos.y)

Does it matter what order they go in?