CodeCombat - Salted Earth[SOLVED]

Why won’t my hero go get the coins? Help, please!

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

Could @thebagel or @Deadpool198 help me? (They’re the only ones I basically know)

Could somebody PLEASE help me?

Make that:

x = item.pos.x
y = item.pos.y

You are creating a variable and assigning that variable a value. When you do that, you need to use one equal sign. The double equal sign is to check if something is equal to something else. The other way you could do this is to just move like this:

hero.moveXY(item.pos.x, item.pos.y)

Thank You! It worked!

1 Like

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