The Two Flowers (python) help needed

I have tried defending the peasant both by letting the soldiers attack their own nearest enemy (which seems to draw enemies away from the peasant) and by giving the defend command. That last one works quite some time, but eventually the peasant will get stuck in a corner and the friendly soldiers will get overwhelmed by the large number of enemies.

What am I doing wrong?

PS. when will the game get some proper level hints and have an option to skip a level? I’m playing this with my kid and it really takes all the fun out when there is no way to progress.

# 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 soldier in soldiers:
        hero.command(soldier, "defend", peasant)
            
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
    items = hero.findItems()
    for item in items:
        coin = hero.findNearestItem()
        hero.move(coin.pos)

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

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

Welcome to the forum Goodie! Getting frustrated is a given aspect of programming…we rarely hit the correct solution the first time.

EDIT: I just re-read your post. How did you have your soldiers attack the nearest enemy? (Please show that code.) It is oft said that Hector must be protected. While true, it is not ultimate…if he takes a hit, it’s a minor setback, if he takes many, it means defeat. Setbacks can/will be overcome.

Thanks for responding. The code I used for attacking the nearest enemy is:

# 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 soldier in soldiers:
        enemies = soldier.findEnemies()
        enemy = soldier.findNearest(enemies)
        hero.command(soldier, "attack", enemy)
            
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
    items = hero.findItems()
    for item in items:
        coin = hero.findNearestItem()
        hero.move(coin.pos)

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

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

I ran it with your code and it worked just fine. How are you fitted for boots and which hero are you playing with? I used Anya and Boots of Leaping…I don’t think I had the ring of speed when I first completed this, but that might be a consideration too.

I did notice that you can trim down your code by a few lines, making it more efficient and quicker. In your ‘def commandSoldiers’, make the for loop the first line of the definition…like:

for each soldier in hero find by type, soldier
then, assign the nearest enemy
if there is one, command that soldier to attack

The for loop will iterate through all available soldiers, so if one gets killed, or others are summoned, a fresh set is found every time you call commandSoldiers(). This same method can also be applied to your pickup coins definition.

Thanks for the help! It was the ring of speed that made the difference.

1 Like

Glad to have helped!

wheres my dad???i need help on that level…i cant seem to find my dad

For some strange reason, I can’t get into the level itself. It keeps saying “Unable to Load Level” and I have been trying for a couple of days now. Can someone please tell me how to fix this problem. I’d really appreciate it.

Hi @abc, please don’t post the same in two locations, it won’t get you help any faster and it clutters the forum.
Please continue on this topic: The Two Flowers
Thanks
Danny

where can i get the ring of speed???

Please dont revive dead topics if it is not about the topic

too late. and it is about the topic

No this topic is about the two flowers

yeah thats where i am and de dedreous sayed something about the ring of speed

That doesn’t mean it is the same topic anyway you buy it from the big item chess of something.

whats the big item chest of something?


See that chese in the bottom roght corner

ohh i got it but im too poor im gems so i cant buy it

:cry: …djhsthbdt

Please don’t spam (:sob: adfadsfasdfasdfasdfasd :sob:)
Lydia