How to collect items in Salted Earth


#1

When I try to collect items, I just attack the enemy. 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)
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 == “gem” or item.type == “coin”:
hero.findNearestItem()


#2

@MunkeyShynes, can you insert your post on posting code with beautiful formatting? thanks


#3

Please post your code properly from now on so we can see the structure and formatting. Help us help you. Thanks.

Button01

You haven’t written any code to move to an item’s position. Yes, you have defined item and you are locating items, but unless you move to the item’s position, you aren’t going to collect items.

The last line does nothing and should be replaced with a move or moveXY method.


#4
# 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 == "gem" or item.type == "coin":
        hero.findNearestItem()
        

Better?

Also, how would you collect things?

Wait, when I put a movement command, he runs into poison.


#5

What did you use to move? If you click on any of the methods, you can see the proper format to use them.

The idea here is not to move to a position where there is poison. So, in other words, you want to move to an item’s position as long as it’s not ( != ) poison.


#6

I finished the level

THANKS