# If the peasant is damaged, the flowers will shrink!
peasant = hero.findByType("peasant")[0]
soldier = hero.findByType("soldier")[0]
coin = hero.findNearestItem()
def summonSoldiers():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
# Define the function: commandSoldiers
def commandSoldiers():
for i in range(9):
hero.command(soldier,"defend", peasant)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
hero.move(coin.pos)
while True:
summonSoldiers()
commandSoldiers()
pickUpNearestCoin()
Oh and the problem is the command method I just don’t know how to fix it.
You could try to command your troops to attack the enemy that is the nearest to each troop.
That is how I managed to finish it.
Ok I’ll try that now and hopefully it’ll work.
Does it work? (20 characters)
Here’s my new code:
# If the peasant is damaged, the flowers will shrink!
enemies = hero.findEnemies()
peasant = hero.findByType("peasant")[0]
coin = hero.findNearestItem()
def summonSoldiers():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
# Define the function: commandSoldiers
def commandSoldiers():
for soldier in hero.findFriends():
enemy = soldier.findNearestEnemy()
if enemy:
hero.command(soldier, "attack", enemy)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
items = hero.findItems()
nearestCoin = hero.findNearest(items)
if nearestCoin:
hero.move(nearestCoin.pos)
while True:
summonSoldiers()
commandSoldiers()
pickUpNearestCoin()
My hero collects gold for a bit but then when the commandSoldiers() function happens he stops and my soldiers don’t do anything
You should check if the friend’s type is “soldier” and if it is a soldier attack. You put the peasant to attack, but he can’t do that.
Ok, so should I use Hero.findByType = soldier?
This should be your if on line 15:
if enemy and soldier.type == "soldier":
Did you completed the level, @Kn1ght_Rag3?
Yes! and it was all thanks to you, @AnSeDra! I’ve been stuck on this level for ages and now I’ve completed it with your help. Thanks so much!
No problem. I am glad I could help.
And enjoy your Flower Ring
Thanks. Btw I also got the boss star 2
Btw I just got the boss star 4 and completed Kelvintaph Defiler with the bonus.