How do you do the level double cheek?[SOLVED]

i was working on this level and one of my code lines it says “try hero.pos”

here is my code

# First, defeat 6 ogres.
# Then collect coins until you have 30 gold.

# This variable is used for counting ogres.
defeatedOgres = 0
coin = hero.findNearestItem()

# This loop is executed while defeatedOgres is less than 6.
while defeatedOgres < 6:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
        defeatedOgres += 1
    else:
        hero.say("Ogres!")

# Move to the right side of the map.
hero.moveXY(49, 36)

# This loop is executed while you have less than 30 gold.
while hero.gold < 30:
    # Find and collect coins.
    hero.moveXY(coin.pos.x, coin.pos.y)          this is the line with the problem
    # Remove this say() message.
    hero.say("I should gather coins!")

# Move to the exit.
hero.moveXY(76, 32)

You have to find the nearest item within the while loop and define it as coin. You also have to remove the hero.say("I should gather coins!") statement.

ok so do i move the "coin = hero.findNearestItem into the loop?

this is what it looks like

Yes, do that and add an if loop checking for a coin.

if coin:
   #move to the coin's position

Try doing hero.move(coin.pos)

@logan_jordan’s boots do not allow him to do that.

ok i will do that right away

Just buy boots that do they aren’t expensive.

No, he gets those in mountains.

i completed the level thanks guys

Great but who’s post helped you solve the problem

Use move since it goes to the nearest coin that is sees now instead of the one that was from 1sec ago. This is very important in the mountains.

Milton, hes not in mountains yet hes not suppose to use move in the desert yet.

It is a good skill and i learned it in the Forest. But the more you know the better :wink:

also i have been using move since the forest