[SOLVED] Two Flowers Python


I tried reading other topics already, they didn’t help
I’m getting the “code is really slow or never finished” warning

My code:

# If the peasant is damaged, the flowers will shrink!

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

# Define the function: commandSoldiers
def commandSoldiers():
    friends = hero.findFriends()
    for friend in friends:
        enemy = friend.findNearestEnemy()
        soldiers = hero.findByType("soldier")
        for soldier in soldiers:
            hero.command(soldier, "attack", enemy)

# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
    item = hero.findNearestItem()
    if item:

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

while True:
    # commandSoldiers()
    # pickUpNearestCoin()


Help? Someone? Please?


The problem is in your commandSoldiers() function. You need an if enemy in there. Also, you don’t need to define soldier, but you need to only command soldiers (you can’t command the peasant), so you need to include a statement to the effect of, if friend.type == "soldier". I was able to get your code to work by just changing the last three lines of the commandSoldiers() function.


Thanks! It worked. (Now doing this to fit 20 characters)