My code runs like this. I move to make the catapults kill the brawlers and themselves, but after my troops kill the witch, they just stop attacking. Help?
This is quite a confusing structure. A triple for loop will not work very well.
Remember that the second and third for loops will only run when the first for loop runs. The first for loop will only run when there are witches. So if there are no witches will it run?
Danny
Hmmmm, I never thought about that. Now that I’ve changed my code, it does the same thing. The troops kill the witch and then just stand still. Here it is.
while True:
command()
move()
def command():
friends = hero.findFriends()
witch = hero.findNearest(hero.findByType("witch"))
for friend in friends:
enemy = friend.findNearestEnemy()
if witch:
hero.command(friend, "attack", witch)
elif enemy.type != "witch":
hero.command(friend, "attack", enemy)
def move():
hero.moveXY(69, 14)
hero.wait(2)
hero.moveXY(15, 14)
I think part of the problem is that you’re using hero.moveXY. While the hero is moving, no other code runs, so your allies tend to just stand there and be killed. Try hero.move instead.
Do you have the Emperor’s Gloves? They’re useful for this level. I found I also needed to be clever about which friend to command to attack which enemy.
Chain lightening works through the walls, so you can help your friends…
It took me 133 lines of code to solve this with the bonus. Admittedly my code isn’t the nicest - I’m sure there’s plenty of people who have done it with fewer lines (and theres a function in there that I didn’t use)! But keep playing with different ways to get different characters doing different things.