Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team


What’s wrong with my code??? My allies can’t kill at least one enemy.

while True:

coin = hero.findNearestItem()
if coin:
if > hero.costOf("soldier"):

for friend in hero.findFriends():
    if friend.type == "soldier":
        distance = hero.distanceTo(friend)
        if distance < 20:
            if < friend.maxHealth:
                if hero.canCast("regen", friend):
                    hero.cast("regen", friend)
        enemy = hero.findNearestEnemy()
        if enemy and > 0:
            hero.command(friend, "attack", enemy)
        if < friend.maxHealth*0.3:
            hero.command(friend, "move", {"x": 24, "y": 46})
            hero.command(friend, "move", {"x": 80, "y": 46})


The code you’ve written is good. It’s just not structured properly. I used your exact code - I changed none of the actual writing - and just moved it around and tabbed it over properly and it successfully completed the level on the first run.

Think about the order of what you need to do. You currently have the section dealing with regen before your attack. Also, your if statement with the retreat command should be tabbed over after the attack command.

Keep messing with it and you’ll get it. It’s just a structure problem.