Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Help with Toil and Trouble (Phyton)

hi. i do exactly what the lvl tells me to do but i still fail. here is my code:

def chooseTarget(friend):
    enemies = hero.findEnemies()
    witch = None
    target = friend.findNearestEnemy()
    for enemy in enemies:
        if enemy.type == "witch":
            witch = enemy
    if friend.type == "soldier" and witch:
        hero.command(friend, "attack", witch)
    if friend.type == "archer" and target:
        hero.command(friend, "attack", target)

while True:
    friends = hero.findFriends()
    for friend in friends:

1 Like

Delete that and put this instead:

witch = friend.findNearest(hero.findByType("witch"))

And for me it worked because soldiers need to attack their nearest witch in order to succed at the level.

1 Like

thanks @AnSeDra. i’ve finished. i need t ago to tennis right now though

Succes! And congratulations on completing the level! :partying_face: