Double Check - item.type?

Here is what I got

defeatedOgres = 0

while defeatedOgres < 6:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
defeatedOgres += 1
else:
hero.say(“Ogres!”)

hero.moveXY(49, 36)

while hero.gold < 30:

coin = hero.findNearestItem()
if item.type == "coin":
    hero.moveXY(coin.pos.x, coin.pos.y)

hero.moveXY(76, 32)

It says that item.type is wrong and says that item is not defined?

1 Like

From what I see, you have defined the nearest item your hero finds as coin and not item.

2 Likes

here’s now what i got( and a sucess :wink: )

defeatedOgres = 0

while defeatedOgres < 6:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
defeatedOgres += 1
else:
hero.say(“Ogres!”)

hero.moveXY(49, 36)
coin = hero.findNearestItem()
while hero.gold < 30:
Find and collect coins.
coin = hero.findNearestItem()
if “coin”:
hero.moveXY(coin.pos.x, coin.pos.y)

hero.moveXY(76, 32)

Good job! :smile: But don’t post solutions as they let users just trying to pass copy the correct code without learning anything.