The Two Flowers - Python Help


#1
def summonSoldiers():
if hero.gold >= hero.costOf("soldier"):
    hero.summon("soldier")


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

peasant = hero.findByType("peasant")[0]


while True:
summonSoldiers()
commandSoldiers()
# pickUpNearestCoin()

I keep getting an error that command’s argument minion should have type unit, but got object: hector


#2

I think you need self.findNearestEnemy


#3
# 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.


#4

it should be for i in range(0,len(soldiers)-1) or something like this
and it should be soldiers[i].findNearestEnemy()


#5

How they showed me and displayed for loops was for i in soldiers[i]:


#6

ok so change friend.findNearestEnemy() to soldier.findNearestEnemy()