Salted earth please help

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)

1 Like
# 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?

2 Likes

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

1 Like

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

this is what it is doing

1 Like
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
1 Like

did you mean to put ‘!’?

3 Likes

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

also

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

2 Likes

I tried doing that it didn’t work for Salted Earth. Are you doing Python?

1 Like

This person’s post was 2 years ago. Don’t you think that George_Huchins_Hun would have asked for more help if he/she could? Please do not revive dead topics.

1 Like

Please do not think up rules.

1 Like

Hi I need help with my code. This is what I have so far,’

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!
    itemPosition = item.pos
        # Put the X and Y coordinates of the item into variables.
    itemX = itemPosition.x
    itemY = itemPosition.y
    hero.moveXY(itemX, itemY)
    gem = hero.findNearestItem()
    coin = hero.findNearestItem()
    # If the item's type is "gem" or "coin":
    if item.type == coin or item.type == gem:
        # Then move and pick it up:
        hero.moveXY(itemX, itemY)

plz help me to improve my skills

1 Like

1 Like

You should remove the lines from 14 to 17 and the lines 22, 23. After that, it should work fine.

1 Like

but then its just says coin not defined. And when I say poison or bottle its keep puting the labels on the coin. And how do you make the hero move away from the poison?

1 Like

Compare this line:

if enemy.type == "munchkin" or enemy.type == "thrower":

with

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

The top one sounds as though it’s working - what’s the difference?

2 Likes

i know its the same but all its says coin not defined

see?

1 Like

The two statements in my last post aren’t quite the same! One’s got " " in, the other one doesn’t…

1 Like

what do you mean? (20)

1 Like

Try putting “coin” and “gem”, rather than coin and gem!

2 Likes