Command's argument problem


#1

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


#2

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


#3

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


#4

array of enemies

friend.findEnemies();

nearest enemy

friend.findNearestEnemy();

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

components tab - API part


#5

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


#6

Check if friend is soldier or archer
Provide full code


#7

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!