Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

[Solved] Stuck on The Two Flowers Python


#1

I’m not sure what’s going wrong with this code exactly, there’s a problem with line 12. It says “command’s argument minion should have type unit, but got object: Hector.”

# 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():
    for soldier in hero.findFriends():
        enemy = soldier.findNearestEnemy()
        if enemy:
            hero.command(soldier, "attack", enemy)

# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
    item = hero.findItems()
    nearestCoin = hero.findNearest(item)
    if nearestCoin:
        hero.move(nearestCoin.pos)
    
peasant = hero.findByType("peasant")[0]

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

Any help is greatly appreciated!


#2

What type of boss star do you have? Is it number 3?


#3

I’ve got boss star 1


#4

Because if you dont have a boss star 3 then you cant command peasants. If you have a boss star 2 or 1 then put this after you say for soldier in hero.findFriends()
You have to make sure that you are only commanding the soldiers so use this

if soldier.type == "soldier":
     #put the rest of the code here, remember to indent! ;)

and once you have solved this problem pls put Solved in your title
Thanks!


#5

Thanks, that solved it!


#6

No problem! Im happy to help!