SALTED EARTH ! Avoiding poison

I have done everything but I keep running into poison

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

I tried picking many different random spot in case of poison. None worked

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 poiso

# If the item's type is "gem" or "coin":
if item  == "gem" or "coin":
    pos = item.pos
    itemx = pos.x# Then move and pick it up
    itemy = pos.y
    hero.moveXY(itemx, itemy)

Leaving it open now for you guys to add

I need the code to be fully formatted use preformatted text

@Sanjay_Sharma
Welcome to the discourse and please feel free to read the rules page here

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 poiso
  
    # If the item's type is "gem" or "coin":
    if item  == "gem" or "coin":
        pos = item.pos
        itemx = pos.x# Then move and pick it up
        itemy = pos.y
        hero.moveXY(itemx, itemy)

can I get the link to this level it would help

Please check if I did it right

CodeCombat - Coding games to learn Python and JavaScript?

The level is called “Salted Earth”
No. 24 in backwoods forest

what course is this in

Code combat : Backwoods forest Chapter (for boolean logic, relational operations etc)
The exact level/puzzle is called “salted earth”

in this section
change item to item.type == gem or item.type == coin.
change pos = item.pos to itemPosition=item.pos
change itemx and y to have x and y capitalized
instead of the = pos.x and y change it to itemPosition.x and itemPosition.y
and then again on the last last line change hero.move to (item to capital x and y )
I think you should get it see if that works.

1 Like

Thank you champ. That was a top one. It worked but honestly I am still not sure what I did wrong here (learning wise).

Thanks though I can finally move on !

1 Like

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