# Hero Placeholder need something to command error

**URL:** <https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081>\
**Category:** Level Help\
**Created:** [October 27, 2021, 11:21am UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081 "2021-10-27T11:21:01Z")\
**Posts on this page:** 17\
**Page:** 2

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [October 28, 2021, 11:48am UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/21 "2021-10-28T11:48:36Z")

</div>

What i need to change to fix the error?

```python
def commandGriff(enemy):
    griff = hero.findByType("griffin-rider")
    if enemy and griff:
        hero.command(griff, "attack", enemy)
    elif griff:
        hero.command(griff, "move", {'x': 78, 'y': 40})

```

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [October 28, 2021, 11:58am UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/22 "2021-10-28T11:58:41Z")

</div>

> [@Haris](#):
>
> `enemy = hero.findByType("robot-walker")`

The issue is here, you need to change this line, for example to find nearest enemy.

> [@Haris](#):
>
> `def commandTroops():`

Also place the function of this line after all the functions of commanding soldier, archers, etc.

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [October 28, 2021, 12:05pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/23 "2021-10-28T12:05:18Z")

</div>

Like this? `enemy = hero.findNearest(hero.findByType("robot-walker")`?

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [October 28, 2021, 12:37pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/24 "2021-10-28T12:37:24Z")

</div>

Yes, it works (20chars)

---

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [October 28, 2021, 12:44pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/27 "2021-10-28T12:44:38Z")

</div>

whoops wrong topic sry

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [October 28, 2021, 1:04pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/28 "2021-10-28T13:04:28Z")

</div>

@Haris what level is this exactly?

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [October 28, 2021, 2:41pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/29 "2021-10-28T14:41:46Z")

</div>

Kelvintaph Burgler. 20 chars

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [October 28, 2021, 2:44pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/30 "2021-10-28T14:44:13Z")

</div>

I change that but still get the error

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [October 28, 2021, 2:56pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/31 "2021-10-28T14:56:16Z")

</div>

New code? (20 chars)

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [October 28, 2021, 2:58pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/32 "2021-10-28T14:58:43Z")

</div>

here.

```python
coors1 = [0, 0]
coors2 = [0, 0]

def lowestHealthFriend():
    lowestHealth = 99999
    lowestFriend = None
    friends = self.findFriends()
    for friend in friends:
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend

    return lowestFriend

def moveTo(position, fast = True):
    if(self.isReady("jump") and fast):
        self.jumpTo(position)
    else:
        self.move(position)
summonTypes = ['griffin-rider']
def summonTroops():
    type = summonTypes[len(self.built)%len(summonTypes)]
    if self.gold > self.costOf(type):
        self.summon(type)

def commandGriff(enemy):
    griff = hero.findByType("griffin-rider")
    if enemy and griff:
        hero.command(griff, "attack", enemy)
    elif griff:
        hero.command(griff, "move", {'x': 78, 'y': 40})

def commandTroops():
    for index, friend in enumerate(self.findNearest(hero.findFriend())):
        if chieftain and friend.type != 'paladin':
            continue
        if witch and friend.type != 'paladin':
            continue
        if chieftain and chieftain.pos.x<57 and chieftain.pos.x>43:
             self.command(friend, "move", {'x':25, 'y':48})
        elif not chieftain and friend.pos.x<40:
             self.command(friend, "move", {'x':51, 'y':51})
        elif friend.type == 'paladin':
            CommandPaladin(friend)
        elif friend.type == 'soldier':
            if friend.pos.y>30:
                CommandSoldier(friend)
            else:
                KillRobots(friend)
        else:
            CommandArcher(friend)

def CommandPaladin(paladin):
    if(paladin.canCast("heal") and not chieftain):
        target = lowestHealthFriend()
        if target:
            self.command(paladin, "cast", "heal", target)
    elif(paladin.health<100):
        self.command(paladin, "shield")
    else:
        if witch:
            self.command(paladin, "attack", witch)
        elif(chieftain):
            self.command(paladin, "attack", chieftain)
        else:
            self.command(paladin, "move", {'x':78, 'y':40})

def CommandSoldier(soldier):
    if witch:
        self.command(soldier, "attack", witch)
    else:
        self.command(soldier, "move", {'x':78, 'y':40})

def CommandArcher(soldier):
    if witch:
        self.command(soldier, "attack", witch)
    else:
        self.command(soldier, "move", {'x':78, 'y':40})

def KillRobots(soldier):
    robot = self.findNearest(self.findEnemies())
    if robot:
        self.command(soldier, "attack", robot)

def RunFrom():
    missiles = self.findEnemyMissiles()
    missle = self.findNearest(missiles)
    if len(missiles)>0:
        coors1[0] = missle.pos.x
        coors1[1] = missle.pos.y
        y = findTheY(coors1[0], coors2[0], coors1[1], coors2[1], self.pos.x)
        if y >15:
            moveTo({'x':self.pos.x, 'y':10}, False)
        else:
            moveTo({'x':self.pos.x, 'y':20}, False)
        coors2[0] = coors1[0]
        coors2[1] = coors1[1]

            
def findTheY(x1, x2, y1, y2, x):
    if(y2!=y1):
        y = (x - x1)/(x2 - x1)*(y2 - y1) + y1
    else:
        y = y1
    return y

def findTheMiddle(pos1, pos2):
    return {'x':(pos1.x+pos2.x)/2,'y':(pos1.y+pos2.y)/2}

while True:
    #CHill
    witch = self.findNearest(self.findByType('witch'))
    chieftain = self.findNearest(self.findByType('chieftain'))
    
    
    if witch or chieftain:
        RunFrom()
    summonTroops()
    commandGriff(hero.findByType("robot-walker"))
    commandTroops()

```

and i get the error at this part.

```python
def commandGriff(enemy):
    griff = hero.findByType("griffin-rider")
    if enemy and griff:
        hero.command(griff, "attack", enemy)
    elif griff:
        hero.command(griff, "move", {'x': 78, 'y': 40})

```

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [October 28, 2021, 3:17pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/33 "2021-10-28T15:17:59Z")

</div>

> [@Haris](#):
>
> `griff = hero.findByType("griffin-rider")`

This returns a list, you don’t need it this way. Either make a for-loop to get a specific index. (I think for-loops are better)

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [October 28, 2021, 3:39pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/34 "2021-10-28T15:39:44Z")

</div>

Yes finnaly! i don’t get the hero placeholder error but i get i one more error

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [October 28, 2021, 4:17pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/35 "2021-10-28T16:17:32Z")

</div>

![Kelvintaph Burgler - Learn to Code in Python, Java](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/0/d/0d3258521b1d8ea2fb3b96c110d67e003577f130.png)  
look `What that mean?`

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [October 28, 2021, 5:52pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/36 "2021-10-28T17:52:02Z")

</div>

can you repost your code?

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [October 30, 2021, 12:54pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/37 "2021-10-30T12:54:20Z")

</div>

here.

```python
coors1 = [0, 0]
coors2 = [0, 0]

def lowestHealthFriend():
    lowestHealth = 99999
    lowestFriend = None
    friends = self.findFriends()
    for friend in friends:
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend

    return lowestFriend

def moveTo(position, fast = True):
    if(self.isReady("jump") and fast):
        self.jumpTo(position)
    else:
        self.move(position)
summonTypes = ['griffin-rider']
def summonTroops():
    type = summonTypes[len(self.built)%len(summonTypes)]
    if self.gold > self.costOf(type):
        self.summon(type)

def commandGriff(enemy):
    griffs = hero.findByType("griffin-rider")
    for griff in griffs:
        if enemy and griff:
            hero.command(griff, "attack", enemy)
        elif griff:
            +hero.command(griff, "move", {'x': 78, 'y': 40})

def commandTroops():
    for index, friend in enumerate(self.findNearest(hero.findFriend())):
        if chieftain and friend.type != 'paladin':
            continue
        if witch and friend.type != 'paladin':
            continue
        if chieftain and chieftain.pos.x<57 and chieftain.pos.x>43:
             self.command(friend, "move", {'x':25, 'y':48})
        elif not chieftain and friend.pos.x<40:
             self.command(friend, "move", {'x':51, 'y':51})
        elif friend.type == 'paladin':
            CommandPaladin(friend)
        elif friend.type == 'soldier':
            if friend.pos.y>30:
                CommandSoldier(friend)
            else:
                KillRobots(friend)
        else:
            CommandArcher(friend)

def CommandPaladin(paladin):
    if(paladin.canCast("heal") and not chieftain):
        target = lowestHealthFriend()
        if target:
            self.command(paladin, "cast", "heal", target)
    elif(paladin.health<100):
        self.command(paladin, "shield")
    else:
        if witch:
            self.command(paladin, "attack", witch)
        elif(chieftain):
            self.command(paladin, "attack", chieftain)
        else:
            self.command(paladin, "move", {'x':78, 'y':40})

def CommandSoldier(soldier):
    if witch:
        self.command(soldier, "attack", witch)
    else:
        self.command(soldier, "move", {'x':78, 'y':40})

def CommandArcher(soldier):
    if witch:
        self.command(soldier, "attack", witch)
    else:
        self.command(soldier, "move", {'x':78, 'y':40})

def KillRobots(soldier):
    robot = self.findNearest(self.findEnemies())
    if robot:
        self.command(soldier, "attack", robot)

def RunFrom():
    missiles = self.findEnemyMissiles()
    missle = self.findNearest(missiles)
    if len(missiles)>0:
        coors1[0] = missle.pos.x
        coors1[1] = missle.pos.y
        y = findTheY(coors1[0], coors2[0], coors1[1], coors2[1], self.pos.x)
        if y >15:
            moveTo({'x':self.pos.x, 'y':10}, False)
        else:
            moveTo({'x':self.pos.x, 'y':20}, False)
        coors2[0] = coors1[0]
        coors2[1] = coors1[1]

            
def findTheY(x1, x2, y1, y2, x):
    if(y2!=y1):
        y = (x - x1)/(x2 - x1)*(y2 - y1) + y1
    else:
        y = y1
    return y

def findTheMiddle(pos1, pos2):
    return {'x':(pos1.x+pos2.x)/2,'y':(pos1.y+pos2.y)/2}

while True:
    #CHill
    witch = self.findNearest(self.findByType('witch'))
    chieftain = self.findNearest(self.findByType('chieftain'))
    
    
    if witch or chieftain:
        RunFrom()
    summonTroops()
    commandGriff(hero.findByType("robot-walker"))
    commandTroops()

```

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [October 30, 2021, 1:11pm UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/38 "2021-10-30T13:11:59Z")

</div>

> [@Haris](#):
>
> ```python
> def commandTroops():
> for index, friend in enumerate(self.findNearest(hero.findFriend())):
> if chieftain and friend.type != 'paladin':
> continue
> if witch and friend.type != 'paladin':
> continue
> if chieftain and chieftain.pos.x<57 and chieftain.pos.x>43:
> self.command(friend, "move", {'x':25, 'y':48})
> elif not chieftain and friend.pos.x<40:
> self.command(friend, "move", {'x':51, 'y':51})
> elif friend.type == 'paladin':
> CommandPaladin(friend)
> elif friend.type == 'soldier':
> if friend.pos.y>30:
> CommandSoldier(friend)
> else:
> KillRobots(friend)
> else:
> CommandArcher(friend)
> 
> ```

You need to put all of this directly before the `while-true loop`  
But I’m not sure about the error you are getting

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [November 11, 2021, 4:44am UTC](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081/39 "2021-11-11T04:44:19Z")

</div>

noot woorking. 20 chars

[Previous page](https://discourse.codecombat.com/t/hero-placeholder-need-something-to-command-error/31081.md?page=1)
