The Two Flowers Help!

this is my code.

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

# Define the function: commandSoldiers
def commandsoldiers():
    enemy = hero.findNearestEnemy()
    for soldier in hero.findByType("soldier"):
        hero.command(soldier, "attack", enemy)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
peasant = hero.findByType("peasant")[0]

while True:
    pickUpNearestCoin()
    summonSoldiers()
    commandsoldiers()

Honestly I should change the title and put it under bug. Because my code works but the enemies die so late that hector never has time to make the flowers grow even though all the enemies are dead :frowning_face_with_open_mouth:

Hi please send a picture so we can see what is happening

I just run out of time. All of the enemies die, but Hector, the peasant runs out of time to grow the flowers.

what boss star do you own?

Boss star 1. Is that bad?

npoe just if u had bs2 u would hav archers

also try summoning soldiers to defend/attack hector/enemies
and the hero will colect coinz

I did that. The soldiers win. But not in time.

def commandsoldiers():
    enemy = hero.findNearestEnemy()
    for soldier in hero.findByType("soldier"):
        hero.command(soldier, "attack", enemy)

this code is wrong i think

What the heck does that mean…

You say stuff very confusingly.

this actually seems fine. could be cleaner with

def commandsoldiers():
    enemy = hero.findNearestEnemy()
    soldiers = hero.findByType("soldier")
    for soldier in soldiers:
        hero.command(soldier, "attack", enemy)

this seems unnecessary

Ok. I will erase that.

you could put the soldiers around hector and wait for the enemies to get closer using the distance function before attacking them. That would increase the amount of time he has.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.