Hi!
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:
coins.append(item)
coin = hero.findNearest(coins)
hero.move(coin.pos)
Hi!
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:
coins.append(item)
coin = hero.findNearest(coins)
hero.move(coin.pos)
If coin not exist, than move method return error. So, you need to check it before move.
if coin:
hero.move(coin.pos)
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!