Toil and trouble help!

For some reason I can’t figure out this problem, help plz?

You need to also command the archers to attack their nearest enemy; only the soldiers have command code right now. I also suggest commanding the soldiers to attack their nearest enemy if all witches are dead.

something like this? I can’t get it to work but how can check my work?

Just change the “nearestwitch” to “enemy” and you should be fine; the archer should continue attacking even after all the witches are dead.

elif nearestwitch and friend.type == "archer":
        hero.command(friend, "attack", enemy)

doesn’t work…

Your code logic seems messed up. You would want to wrap the witch check into a big if-loop for the ally types.
Also, friend has no method of findNearest, use hero.findNearest(hero.findByType("witch"))

if friend.type == "archer":
if friend.type == "soldier":
    if witch:
    elif enemy:

Anyone got a code I could use? Im going nowhere

Unfortunately we’re not allowed to share full solution code on the Discourse, since it defeats the point of learning.
However, I’ve compared my code and yours and I’ll try to help you complete the level.

  • Firstly, delete lines 10, and 11 (the nearestwitch if loop), you don’t need it. Also replace the elif on line 12 with an if.

  • Below that, on the lines for soldiers, you’re commanding them to just attack the nearest enemy. You want to replace the enemy in hero.command(friend, "attack", enemy) with the nearestwitch variable.

Hopefully this helps

THANK YOU! it worked, I was about to give up when I found something misspelled but the code works now.

No problem, it’s great to know that you’ve solved the level!

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