# If the peasant is damaged, the flowers will shrink!
def summonSoldiers():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
# Define the function: commandSoldiers
def commandSoldiers():
soldiers = hero.findByType("soldier")
for i in soldiers[i]:
hero.command(soldiers[i], "attack", friend.findNearestEnemy())
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
while True:
peasant = hero.findByType("peasant")[0]
summonSoldiers()
commandSoldiers()
pickUpNearestCoin()
Whenever I press run, Tharin has the red X and says that it cannot convert undefined/null to object.
I need help with my code, he summons soldiers and stuff but then he doesn’t do anything else after that,he just stands there, which I expected but he wont command them to attack enemies!
coin = self.findNearest(self.findItems())
self.move(coin.pos)
if hero.time == 10:
break
loop:
if self.gold > self.costOf("soldier"):
self.summon("soldier")
enemy = self.findNearest(self.findEnemies())
if enemy:
# Loop over all your soldiers and order them to attack.
soldiers = self.findFriends()
if hero.findFriends() != "hector":
continue
else:
pass
soldierIndex = 0
while soldierIndex < len(soldiers):
soldier = soldiers[soldierIndex]
enemy = soldier.findNearest(enemy)
self.command(soldier, "attack", enemy)
soldierIndex = soldierIndex+1
so what do i do with that part then? i did happen to beat the level by now, but in a different way, the wrong way but i beat it, however it would be good to know how to do that.