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!
if hero.gold >= hero.costOf("soldier"):
# Define the function: commandSoldiers
soldiers = hero.findByType("soldier")
for soldier in soldiers:
hero.command(soldier, "defend", peasant)
# Define the function: pickUpNearestCoin
items = hero.findItems()
for item in items:
coin = hero.findNearestItem()
peasant = hero.findByType("peasant")
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.
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.
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.