Salted earth please help


#1


#2

you need to put something after your “if” statement on line 12.
currently, your code does this in this order :

  • Finds the nearest enemy
  • checks if that nearest enemy is a munchkin or a thrower
  • if it is a munchkin or thrower, attack it
  • finds the nearest item
  • checks if that item is a coin or a gem

Notice how it looks a bit incomplete at the end? You are checking for an item and then doing nothing from there on, you need to follow up your ‘if’ statement on line 12 with something.

(Checks previous levels if you aren’t sure on how to move to an item’s X and Y coordinates)


#3
# 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)
    item = hero.findNearestItem()
    # Check the item type to make sure the hero doesn't pick up poison!
    # Look for types: 'gem' and 'coin'
    if item.type == "coin" or item.type == "gem":
        hero.moveXY(item.pos.x, item.pos.y)

is this better?


#4

I’m not sure, is it? What errors are you getting now?


#5

none i beat the level thanks can you help me do cursed wonderglade?

this is what it is doing


#6
while True:
    item = hero.findNearestItem()   
    if item.type != "gem":
        hero.moveXY(item.pos.x, item.pos.y)
    # Find the nearest enemy.
    # Attack it if it exists and its type isn't "burl".
    enemy = hero.findNearestEnemy()
    if enemy.type != "burl":
        hero.attack(enemy)
    pass
this is my code

#7

did you mean to put ‘!’?


#8

if item AND item.type != “gem”:

also

if enemy AND enemy.type != “burl”: