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

Nearest Gold Coin


I’m trying to pick up only the closest gold coins.
Why does this not work?

coins = []
for item in hero.findItems():
    if item.value == 3:
coin = hero.findNearest(coins)


If coin not exist, than move method return error. So, you need to check it before move.

if coin:


RobAnybody has the answer. If there are no Gold Coins on the map your list will be empty. In which case there is no coin to take the coin.pos of. Hero.move(coin.pos) will be empty. And moving without a position returns an error.


Thank you!
That helped!


Thanks a lot for the explanation!