Vital Powers Help plz


#1

I need help with my code and there are no errors.
My code:

# This level shows how to define your own functions.
# The code inside a function is not executed immediately. It's saved for later.
# This function has your hero collect the nearest coin.
def pickUpNearestCoin():
    items = self.findItems()
    nearestCoin = self.findNearest(items)
    if nearestCoin:
        self.move(nearestCoin.pos)

# This function has your hero summon a soldier.
def summonSoldier():
    # Fill in code here to summon a soldier if you have enough gold.
    while self.gold > self.costOf("soldier"):
        self.summon("soldier")
    for soilder in soilders:
        if enemy:
            self.command(soilder, "attack", enemy)
    pass


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

loop:
    # 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 her

Is code combat applicable for a 9 year old?
#2
  1. summonSoldier is a function, you need to call it like this:
summonSolider()
  1. You are not calling commandSoldiers() at all in your loop

  2. Leaving sumonSolider like this in your code will definitely produce an error. Run the cod,e you’ll see an red X under the hero. The look on the right for market line where the error appears.


#3

not solider
its soldier


#4

what gear do you have
i recommend a speed ring and good armor i had 3400 health
i did not even have to write a code and i solved it


#5

plus you dont need to do pickup nearest coin at the end
define enemy
define soilder


#6

actually you do need to do pickupNearest at the end but just add commandSoldier() at the end


#7

Thanks for the advice.


#8

What do you mean??:open_mouth:


#9

This is my code and there is a red X mark under my hero.

# This level shows how to define your own functions.
# The code inside a function is not executed immediately. It's saved for later.
# This function has your hero collect the nearest
enemy = self.findEnemies()
soilder = self.findFriends()
def pickUpNearestCoin():
    items = self.findItems()
    nearestCoin = self.findNearest(items)
    if nearestCoin:
        self.move(nearestCoin.pos)

# This function has your hero summon a soldier.
def summonSoldier():
    # Fill in code here to summon a soldier if you have enough gold.
    while self.gold > self.costOf("soldier"):
        self.summon("soldier")
    for soilder in soilders:
        if enemy:
            self.command(soilder, "attack", enemy)
    pass


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

loop:
    self.summon("soldier")
    self.command(soilder, "attack", enemy)
    # 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
    commandSoilders()

#10

just take out
at the bottom

self.summon("soldier")
and also
self.command(soilder, "attack", enemy)


#11

like this

loop:
    # 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 her
    commandSoldiers()

at the end


#12

It still does not work.

## This function has your hero summons
def summonSoldier():
    # Fill in code here to summon a soldier if you have enough gold.
    while self.gold > self.costOf("soldier"):
        self.summon("soldier")
    for soilder in soilders:
        if enemy:
            self.command(soilder, "attack", enemy)
    pass


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

loop:
    # 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()

It says pick up nearest coin is not defined


#13

Thanks for the advice though.


#14

Nvm I beat it
Thx
Yay