[SOLVED]Plz help with sarven-siege


#1

can’t get hero to build solider after collecting 20 coins, it would just collect up to 27 and stop
litte help would be very kind

def collectCoin():
    coins = hero.findItems()
    bestCoin = 0
    bestValue = 0
    for coin in coins:
        value = coin.value/hero.distanceTo(coin)
        if value > bestValue:
            bestValue = value
            bestCoin = coin
    if bestCoin:
        hero.moveXY(bestCoin.pos.x, bestCoin.pos.y)
        
        
while True:
    coin = hero.findNearestItem()
    gold = hero.gold
    while gold <= 20:
        collectCoin()
        break


    
while hero.gold >= 20:
    arrowTower=self.findByType("arrow-tower")
    nearestTower=self.findNearest(hero.findByType("arrow-tower"))
    if nearestTower:
        hero.moveXY(nearestTower.pos.x + 5, nearestTower.pos.y)
        break


#2

Instead of your

while hero.gold > 20, 
#use 
if hero.gold > 20

#3

Because if questions it, while says that while it is at it, and it is not.


#4

Thank you guys, I’ll try That asap :slight_smile:


#5

solved it, thanks a lot :slight_smile:


#6

Good job, you did it by yourslef!