# \[SOLVED\] Timber Guard help please

**URL:** <https://discourse.codecombat.com/t/solved-timber-guard-help-please/22520>\
**Category:** Level Help\
**Created:** [June 24, 2020, 1:57pm UTC](https://discourse.codecombat.com/t/solved-timber-guard-help-please/22520 "2020-06-24T13:57:03Z")\
**Posts on this page:** 3\
**Page:** 3

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [June 25, 2020, 1:48pm UTC](https://discourse.codecombat.com/t/solved-timber-guard-help-please/22520/41 "2020-06-25T13:48:59Z")

</div>

Then congratulations for completing the level! 🥳

---

<div class="post-metadata">

**Author:** ![Cedar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cedar/32/29302_2.png) [@Cedar](https://discourse.codecombat.com/u/Cedar)\
**Post date:** [June 9, 2022, 4:57pm UTC](https://discourse.codecombat.com/t/solved-timber-guard-help-please/22520/42 "2022-06-09T16:57:33Z")

</div>

My code won’t work… I can’t get the soldiers to attack the ogres.  
My code:

```python
gold = hero.findNearestItem()
if gold:
    hero.moveXY(gold.pos.x, gold.pos.y)
# If you have enough gold, summon a soldier.
if hero.gold > hero.costOf("soldier"):
    hero.summon("soldier")
# Use a for-loop to command each soldier.
# For loops have two parts: "for X in Y"
# Y is the array to loop over.
# The loop will run once for each item in Y, with X set to the current item.
for friend in hero.findFriends():
    if friend.type == "soldier":
        enemy = friend.findNearestEnemy()
        defendPos = {"x": 91, "y":40}
        # If there's an enemy, command her to attack.
        # Otherwise, move her to the right side of the map.
        if enemy:
            hero.command(friend, "attack", enemy)
        else:
            hero.command(friend, "move", defendPos)

```

---

<div class="post-metadata">

**Author:** ![Cedar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cedar/32/29302_2.png) [@Cedar](https://discourse.codecombat.com/u/Cedar)\
**Post date:** [June 9, 2022, 4:59pm UTC](https://discourse.codecombat.com/t/solved-timber-guard-help-please/22520/43 "2022-06-09T16:59:20Z")

</div>

never mind. I fixed it.

[Previous page](https://discourse.codecombat.com/t/solved-timber-guard-help-please/22520.md?page=2)
