[SOLVED] Plz help I can't figure out how to beat it

I need help plz, here is my code:
defeatedOgres = 0
while defeatedOgres < 6:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
defeatedOgres += 1
else:
hero.say(“Ogres!”)
hero.moveXY(53, 37)
while hero.gold < 30:
item = hero.findNearestItem()
if item and item.type == “coin”:
hero.moveXY(item.pos.x, item.pos.y)
Coin = hero.findItems(hero.findNearestItem())
Coin = hero.findnearestItem
hero.move(coin.pos)
hero.say(“I should gather coins!”)
hero.moveXY(76, 32)

Its’s Double Cheek in code combat

Could you please post your code correctly as it says in this
Lydia

I’m new I don’t know how

Lydia

``````defeatedOgres = 0
while defeatedOgres < 6:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
defeatedOgres += 1
else:
hero.say("Ogres!")
hero.moveXY(53, 37)
while hero.gold < 30:
item = hero.findNearestItem()
if item and item.type == "coin":
hero.moveXY(item.pos.x, item.pos.y)
Coin = hero.findItems(hero.findNearestItem())
Coin = hero.findnearestItem
hero.move(coin.pos)
hero.say("I should gather coins!")
hero.moveXY(76, 32)

``````

Is this how i do it?
Ryan

Replace this:

With this:

``````while hero.gold < 30:
# Find and collect coins.
gold = hero.findNearestItem()
hero.moveXY(gold.pos.x, gold.pos.y)
``````

I also see that you’ve deleted a comment.
`# Remove this say() message.`
Do what the comment says to do and you should be all set to move on!
Lydia

2 Likes

oh ok I did it and it worked! Thank you!

1 Like