Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Vital powers (Confused)

here is my code.

def summonSoldier():
    # Fill in code here to summon a soldier if you have enough gold
    if self.gold >= self.costOf("soldier"):
        self.summon("soldier")
    else: 
        break
# This function commands your soldiers to attack their nearest enemy.
def commandSoldiers():
    soldiers = self.findFriends()
    if soldiers:
        for soldier in self.findFriends():
            target = soldier.findNearest(soldier.findEnemies())
            if target:
                self.command(soldier, "attack", target)
def pickUpNearestCoin():
    while self.gold < self.costOf("soldier"):
        coin = self.findNearest(self.findItems())
        self.moveXY(coin.pos.x, coin.pos.y)
         
    # In your loop, you can "call" the functions defined above.
    # The following line causes the code inside the "pickUpNearestCoin" function to be executed.
    pickUpNearestCoin()
    # Call summonSoldier here
    summonSoldier()
    #Call commandSoldiers here
    commandSoldiers()
while True:
    pickUpNearestCoin()
    summonSoldiers()
    commandSoldiers()

It keeps on saying this

i’ll just reset the level but what was wrong with my code?

def pickUpNearestCoin():
    items = hero.findItems()
    nearestCoin = hero.findNearest(items)
    if nearestCoin:
        hero.move(nearestCoin.pos)

# This function has your hero summon a soldier.
def summonSoldier():
    # If hero.gold is greater than the cost of the "soldier":
    if hero.gold>hero.costOf("soldier"):
        # Then summon a "soldier":
        hero.summon("soldier")
    pass


# This function commands your soldiers to attack their nearest enemy.
def commandSoldiers():
    for soldier in hero.findFriends():
        enemy = soldier.findNearestEnemy()
        if enemy:
            hero.command(soldier, "attack", enemy)

while True:
    # In your loop, you can "call" the functions defined above.
    # The following line causes the code inside the "pickUpNearestCoin" function to be executed.
    pickUpNearestCoin()
    # Call summonSoldier here
    summonSoldier()
    # Call commandSoldiers here
    commandSoldier()

What is wrong with my code now it says that I have an error but doesn’t show what it is?

never mind finished the level