# Borrowed Sword- I'm so lost

**URL:** https://discourse.codecombat.com/t/borrowed-sword-im-so-lost/28009
**Category:** Level Help
**Created:** [March 18, 2021, 11:45pm UTC](https://discourse.codecombat.com/t/borrowed-sword-im-so-lost/28009 "2021-03-18T23:45:34Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Michael\_Goff](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/michael_goff/32/21518_2.png) [@Michael\_Goff](https://discourse.codecombat.com/u/Michael_Goff)
#### Post date: [March 18, 2021, 11:45pm UTC](https://discourse.codecombat.com/t/borrowed-sword-im-so-lost/28009/1 "2021-03-18T23:45:34Z")

</div>

# For this level, your hero doesn’t fight.

# Command your archers to focus fire on the enemy with the most health!

```python
while True:
    enemies = hero.findEnemies()
    friends = hero.findFriends()
    bestHealth = 0
    best = 0
    for i in range(len(friends)):
        friend = friends[i]
    
    for enemy in enemies:
        if enemies.health > bestHealth:
            bestHealth = enemies.health
            best = enemy
    
    if bestHealth:
        hero.command(friend, "attack", best)

```

---

<div class="post-metadata">

### Author: ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)
#### Post date: [March 19, 2021, 12:37am UTC](https://discourse.codecombat.com/t/borrowed-sword-im-so-lost/28009/2 "2021-03-19T00:37:27Z")

</div>

Take a closer look at your for loop for the enemies and make sure you are using the correct variable to identify the health of each enemy. The last line of the for loop is correct `best = enemy`.

---

<div class="post-metadata">

### Author: ![Michael\_Goff](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/michael_goff/32/21518_2.png) [@Michael\_Goff](https://discourse.codecombat.com/u/Michael_Goff)
#### Post date: [March 19, 2021, 12:56am UTC](https://discourse.codecombat.com/t/borrowed-sword-im-so-lost/28009/3 "2021-03-19T00:56:28Z")

</div>

```python
while True:
    enemies = hero.findEnemies()
    friends = hero.findFriends()
    bestHealth = 0
    best = 0
    for i in range(len(friends)):
        friend = friends[i]
    
    for enemy in enemies:
        if enemy.health > bestHealth:
            bestHealth = enemy.health
            best = enemy
    
    if bestHealth:
        hero.command(friend, "attack", best)

```

i’m assuming like this but now all the Yetis are alive and destroy me

---

<div class="post-metadata">

### Author: ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)
#### Post date: [March 19, 2021, 1:10am UTC](https://discourse.codecombat.com/t/borrowed-sword-im-so-lost/28009/4 "2021-03-19T01:10:50Z")

</div>

Yes, that section looks better.

The key is to command every friend to attack the same best enemy. The order of the code makes a difference in how it is executed. A better arrangement might go like

1. Identify best enemy
2. command all friends to attack the same best enemy

Think about how you would need to arrange the code to command each friend to attack the same best enemy.

One last little note, it is better to check the same variable that you are attacking. While the code will run when you check bestHealth, it isn’t really looking for the enemy you plan to attack. In this case, they are tied together so it will effectively run, but later on it may get you into trouble when you check for one thing and attack another.

---

<div class="post-metadata">

### Author: ![Michael\_Goff](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/michael_goff/32/21518_2.png) [@Michael\_Goff](https://discourse.codecombat.com/u/Michael_Goff)
#### Post date: [March 19, 2021, 3:07pm UTC](https://discourse.codecombat.com/t/borrowed-sword-im-so-lost/28009/5 "2021-03-19T15:07:26Z")

</div>

Ah I finally got it, I see what you mean with the order now.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)
#### Post date: [March 20, 2021, 3:07am UTC](https://discourse.codecombat.com/t/borrowed-sword-im-so-lost/28009/6 "2021-03-20T03:07:51Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
