Need help Vital Powers Lv1 CS5 SOO Annoying (urgent)

Im normally not the one to ask for help but this has been at my plate and I need to get on track because I’ve been on this for 2 weeks and I will have a 0 as my major in the grade book so this is urgent it due in 5 days and basically what is happening is I try to get a lot of coins but as I get coins the enemies come out and its like my character only knows how to fight as it sees an emeny and for some reason start to kill the enemies and doesn’t grab coins in the process and dies trying to fight. I’m stuck and there is absolutely no errors in my code. Here is my code and this is a photo of what happens right before I die and this is my hero inventory

# http://codecombat.com/play/level/vital-powers
def pickUpNearestCoin():
    items = hero.findItems()
    nearestCoin = hero.findNearest(items)
    if nearestCoin and hero.distanceTo(nearestCoin) < 30:
        if hero.isReady("jump"):
            hero.jumpTo(nearestCoin.pos)
        else:
            hero.move(nearestCoin.pos)



def summonSoldier():
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")


def commandSoldiers():
    for soldier in hero.findFriends():
        enemy = soldier.findNearestEnemy()
        if enemy:
            hero.command(soldier, "attack", enemy)


def attack(target):
    if target:
        if (hero.isReady("jump") and hero.distanceTo > 10):
            hero.jumpTo(target.pos)
        elif (hero.isReady("bash")):
            hero.bash(target)
        elif (hero.canCast('chain-lightning', target)):
            hero.cast('chain-lightning', target)
        else:
            hero.attack(target)


def tacktick():
    enemies = hero.findEnemies()
    nearest = hero.findNearest(enemies)
    friends = hero.findFriends()
    if nearest and (hero.distanceTo(nearest) < 10 or hero.now() > 25):
        attack(nearest)
    elif nearest and len(friends) / 3 < len(enemies):
        attack(nearest)
    else:
        pickUpNearestCoin()
 
while True:
    (tacktick)
    summonSoldier()
    commandSoldiers()


while True:


for Vital Powers you will need to prioritize collecting gold over attacking enemies
the attacking enemies part is just to help you get the bonus

1 Like

@Kyilan_Davis-Kramer I see the problem, try putting a while true-loop

delete everything after commanding the soliders, and put this code, it should work

while True:
    
    
    pickUpNearestCoin()
    
    summonSoldier()
    
    commandSoldiers()

I see

Your distanceTo does not have a parameter, usually it is supposed to be hero.distanceTo(target)

ty your a lifesaver and thank you to all those who also tried to help me in this post

already did, it was just because that I wasn’t able to prioitize the coins over fighting the soldiers like @JustALuke said. So which your help helped me so thank you again

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.