Salted earth please help

Please post your code formatted correctly.
Lydia

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!
    # If the item's type is "gem" or "coin":
    enemy = hero.findNearestEnemy()
    if  item.type == "coin" or item.type == "gem":
        itemY = hero.distanceTo(item)
        itemX = hero.distanceTo(item)
        # Then move and pick it up:
        hero.moveXY(itemY, itemY)
        # Write boolean or using 'or'
    hero.say(False or False) # Hero says 'False'
    hero.say(False or True) # Hero says 'True'
    hero.say(True or False) # Hero says 'True'
    hero.say(True or True) # Hero says 'True'
        
here it is, can you please help me

Hi floridamanog,

Have another look at these two lines. You don’t want to know how far away the item is; you want to know the co-ordinates of its position.

Also, I don’t seem to have the hero.say lines you have at the bottom. Are they something you’ve added?

Jenny

Thanks dude i did code and it worked

Glad he helped even long after he posted. Good replies can do that :wink:.

I HAVE DONE EVERYTHING. I KEEP RUNNING INTO POISON. I even tried picking a random spot in case of poison item. It works but eventually it runs into the corner poison

Hey do not post here as it revives topics. In this case this was 4 years ago, if you have a question feel free to make it a topic in level help as I’m trying to help you with now at the moment.

Welcome @Sanjay_Sharma, could you please attach a screenshot and your code so we know what is your problem?

And @Kyilan_Davis-Kramer, since this is still relevant, so it is nothing wrong reviving a topic rather than creating a new one (both bump it up)

2 Likes

Here have a look.

The problem is if item == "gem" or "coin". Python does not directly know what is the coin. You need to use if item == "gem" or item == "coin", comparing it again