Command's argument problem

I just don’t understand what’s wrong with this code? I also tried this code in different level and code works.


I equip Twilight Glasses, Quartz Sense Stone, Boss Star II, Simple Wristwatch

You are trying to command a hero
add checks
the fact that friend
archer or soldier

Tell me, please, how my code should look like? I tryed this:
friend = hero.findFriends()
enemies = friend.findEnemies()
or
enemies = friend.findNearestEnemy()
but got same problems: “friend has no method findEnemies

array of enemies

friend.findEnemies();

nearest enemy

friend.findNearestEnemy();

all supported methods
https://codecombat.com/editor/thang/soldier-m

components tab - API part

friend.findEnemies() causes a problem: “friend has no method findEnemies
friend.findNearestEnemy() causes a problem: friend has no method findNearestEnemy

Check if friend is soldier or archer
Provide full code
https://discourse.codecombat.com/uploads/short-url/8UqhtwABuPykp3tLE7EpCSr2UOu.png

2 Likes

Yep, it works. I was using this code:

def commandArcher(archer):
    friend = hero.findFriends()
    enemies = friend.findEnemies()
    nearest = friend.findNearestEnemy()
    if enemies:
        hero.command(friend, "attack", enemies)
    elif nearest:
        hero.command(friend, "attack", nearest)

instead of this:

def commandArcher(archer):
    friend = hero.findFriends()
    if friend == 'archer':
        enemies = friend.findEnemies()
        nearest = friend.findNearestEnemy()
        if enemies:
            hero.command(friend, "attack", enemies)
        elif nearest:
            hero.command(friend, "attack", nearest)

Thanks!