[SOLVED]Help Salted Earth

I know that there are many of these “salted earth” questions but i just can’t seem to ever get the gem or coin if you could help here is my code

# Ogres are attacking a nearby settlement!
# Be careful, though, for the ogres have sown the ground with poison.
# Gather coins and defeat the ogres, but avoid the burls and poison!

while True:
    enemy = hero.findNearestEnemy()
    if enemy.type == "munchkin" or enemy.type == "thrower":
        hero.attack(enemy)
    # Check the item type to make sure the hero doesn't pick up poison!
    # If the item's type is "gem" or "coin":
    pos = item.pos
    x = pos.x
    y = pos.y
    if item.type == "gem" or "coin":
        # Then move and pick it up:
        item = hero.findNearestItem()
        hero.moveXY(item.pos)

delete

pos = item.pos
    x = pos.x
    y = pos.y

and hero.moveXY() should look like this hero.moveXY(item.pos.x, item.pos.y)

thanks but after i did that it said that it cannot read the type of “undefined” on line 11

can you show me your new code

sure thing!

while True:
    enemy = hero.findNearestEnemy()
    if enemy.type == "munchkin" or enemy.type == "thrower":
        hero.attack(enemy)
    # Check the item type to make sure the hero doesn't pick up poison!
    # If the item's type is "gem" or "coin":
    if item.type == "gem"or "coin":
        # Then move and pick it up:
        item = hero.findNearestItem()
        hero.moveXY(item.pos.x, item.pos.y)

It should be this

if item.type == "gem" or item.type == "coin":

instead of this:

Thank you so much @milton.jinich!

1 Like

You are welcome. Please mark whichever post helped solve your problem with that little :white_check_mark:

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.