Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Metal Detector - Python


I got problem with this level. I’m not sure if I made mistake in code and hero saying distance to coin few times and thats why cannon shots once in front of hero then twice at coin and again twice at top coin after ogre collect it.


Each coin has a unique identifier
You can not just use id "Gold Coin"
Use findNearest() and findItems()


I know this one work but is it optimal solution for this exercise?

def coinDistance():
# Find the nearest coin,
coin = hero.findNearestItem()
# If there is a coin, return the distance to it.
if coin:
distance = hero.distanceTo(coin)
return distance
# Else, return 0 (zero).
return 0

while True:
distance = coinDistance()
if distance > 0:
# Say the distance.


Solution corresponds to that expected of you

This may cause an error
your current glasses do not have this skill



hero.findByType( “coin” )


Thanks for help! :slight_smile: