How to pick up gold?

Hi.
I am struggling in the multiplayer treasure grove mainly because my hero goes after bronze coins rather than going after the gold coins. Is there any way for my hero to give preference to the gold coins?

while True:
    item = hero.findNearestItem()
    if item:
        hero.moveXY(item.pos.x, item.pos.y)
    flag = hero.findFlag("green")
    if flag:
        hero.pickUpFlag(flag)
1 Like

Do

while True:
    item = hero.findNearestItem()
    if item:
        if item.type=='gold-coin':
            hero.moveXY(item.pos.x, item.pos.y)

Try that :wink:

You can make your hero go for gold coins, or you can make your hero go for the best coins.
One way to make your hero go for the best coins is find all the coins, compare each coins value divided by your distance to them, and then move the the bestcoin.

while True:
    items = hero.findItems()
    bestItem = None
    bestValue = 0
    itemsIndex = 0
    # Loop over the items array.
    # Find the item with the highest valueOverDistance()
    while itemsIndex < len(items):
        item = items[itemsIndex]
        if item.value / hero.distanceTo(item) > bestValue:
            bestItem = item
            bestValue = item.value / hero.distanceTo(item)
        itemsIndex += 1
    if bestItem:
        hero.moveXY(bestItem.pos.x, bestItem.pos.y)
            

This does depend however on which programmaticon you have, but I find that this tactic works the best. You will come across this technique in the campaign, so if you don’t get it now, you will soon.
Hope this helps.

1 Like

I would just like to point out that this code wouldn’t work, as if the nearest coin isn’t a gold coin, then the hero wouldn’t do anything because they have no instructions for that eventuality.

That is the code for only gold coins dude.

1 Like

Yeah this code doesn’t seem to work.
my hero just collects random coins even if there are gold coins.

while True:
    item = hero.findNearestItem()
    enemy = hero.findNearestEnemy()
    if enemy:
        ready = hero.isReady("cleave")
        if ready:
            hero.cleave(enemy)
        else:
            hero.attack(enemy)
    if item:
        if item.type=='gold-coin':
            hero.moveXY(item.pos.x, item.pos.y)
        else:
            hero.moveXY(item.pos.x, item.pos.y)

This is what I tried.

1 Like

I just gave you the standard code for Only Gold Coins

2 Likes

then you wouldn’t need to specify gold coins right?

1 Like

If you want to pick up only gold coins, then you will have to specify it. But if you want to pick up any available items, then a no.