Forest storm - Level Help

It keeps on saying there’s an error in my code:
Screenshot 2022-12-15 9.31.14 PM
MY code:

while True:
    enemy = hero.findNearestEnemy()
    if enemy.type == 'thrower' or enemy.type == 'munchkin':
        hero.attack(enemy)
    item = hero.findNearestItem()
    if item.type == 'gem' or item.type == 'coin':
        hero.moveXY(item.pos.x, item.pos.y)
    pass

You need to check to see if an enemy or item exists before trying to find its properties. To do this, you need to add if enemy and if item to the beginning of your if-statements to check if the item or enemy exists.

1 Like

My hero still dies

\while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        if enemy.type == 'thrower' or enemy.type == 'munchkin':
            hero.attack(enemy)
    item = hero.findNearestItem()
    if item:
        if item.type == 'gem' or item.type == 'coin':
            hero.moveXY(item.pos.x, item.pos.y)
    pass

I figured part of it out, but my hero still dies by lightning

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        if enemy.type != "burl" or "thrower" < 15:
            hero.attack(enemy)
    item = hero.findNearestItem()
    if item:
        if item.type != "gem" or "mushroom" < 15:
            hero.moveXY(item.pos.x, item.pos.y)