# \[SOLVED\] Stuck on hunting party

**URL:** <https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513>\
**Category:** Level Help\
**Created:** [June 24, 2020, 8:57am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513 "2020-06-24T08:57:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![liam\_cutts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/liam_cutts/32/12891_2.png) [@liam\_cutts](https://discourse.codecombat.com/u/liam_cutts)\
**Post date:** [June 24, 2020, 8:57am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/1 "2020-06-24T08:57:41Z")

</div>

````python
type or paste code here
```while True:
    friends = hero.findFriends()
    # Use for-loop and for each friend:
    for friend in friends:
        # If they see an enemy then command to attack
        hero.command(friend, "attack", enemy)
    # Command to move east by small steps.
    hero.command(friend, "move", {"x": friend.pos.x + 5, "y": friend.pos.y})
````

---

<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 24, 2020, 9:00am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/2 "2020-06-24T09:00:58Z")

</div>

Try to format it again, deleting this:

> [@liam\_cutts](#):
>
> `type or paste code here`

---

<div class="post-metadata">

**Author:** ![liam\_cutts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/liam_cutts/32/12891_2.png) [@liam\_cutts](https://discourse.codecombat.com/u/liam_cutts)\
**Post date:** [June 24, 2020, 9:01am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/3 "2020-06-24T09:01:31Z")

</div>

while True:  
friends = hero.findFriends()  
# Use for-loop and for each friend:  
for friend in friends:  
# If they see an enemy then command to attack  
hero.command(friend, “attack”, enemy)  
# Command to move east by small steps.  
hero.command(friend, “move”, {“x”: friend.pos.x + 5, “y”: friend.pos.y})

---

<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 24, 2020, 9:02am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/4 "2020-06-24T09:02:14Z")

</div>

Can you try one more time?

---

<div class="post-metadata">

**Author:** ![liam\_cutts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/liam_cutts/32/12891_2.png) [@liam\_cutts](https://discourse.codecombat.com/u/liam_cutts)\
**Post date:** [June 24, 2020, 9:03am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/5 "2020-06-24T09:03:04Z")

</div>

```python
while True:
    friends = hero.findFriends()
    # Use for-loop and for each friend:
    for friend in friends:
        # If they see an enemy then command to attack
        hero.command(friend, "attack", enemy)
    # Command to move east by small steps.
    hero.command(friend, "move", {"x": friend.pos.x + 5, "y": friend.pos.y})

```

---

<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 24, 2020, 9:04am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/6 "2020-06-24T09:04:09Z")

</div>

Your code is well formated. Now I will tey to hwlp you solve the level.

---

<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 24, 2020, 9:05am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/7 "2020-06-24T09:05:16Z")

</div>

> [@liam\_cutts](#):
>
> `hero.command(friend, "attack", enemy)`

Before that you forgot to put that in the variabile enemy is friend’s nearest enemy and check if it exists and only then attack.  
Do you need any more assistance at this level?

---

<div class="post-metadata">

**Author:** ![liam\_cutts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/liam_cutts/32/12891_2.png) [@liam\_cutts](https://discourse.codecombat.com/u/liam_cutts)\
**Post date:** [June 24, 2020, 9:07am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/8 "2020-06-24T09:07:28Z")

</div>

so wat should I put in the command

---

<div class="post-metadata">

**Author:** ![liam\_cutts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/liam_cutts/32/12891_2.png) [@liam\_cutts](https://discourse.codecombat.com/u/liam_cutts)\
**Post date:** [June 24, 2020, 9:11am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/9 "2020-06-24T09:11:02Z")

</div>

hello can you show me wat to put in the command please

---

<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 24, 2020, 9:11am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/10 "2020-06-24T09:11:50Z")

</div>

You need to command the friend to attavk the enemy only if the enemy exisis.  
Do you need any more assistance at this level?

---

<div class="post-metadata">

**Author:** ![liam\_cutts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/liam_cutts/32/12891_2.png) [@liam\_cutts](https://discourse.codecombat.com/u/liam_cutts)\
**Post date:** [June 24, 2020, 9:12am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/11 "2020-06-24T09:12:22Z")

</div>

can you show me in code I mean

---

<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 24, 2020, 9:13am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/12 "2020-06-24T09:13:47Z")

</div>

Ok here it is

```python
enemy = friend.findNearestEnemy()
if enemy:
    #here command your friend to attack the enemy

```

Do you need any more assistance at this level?

---

<div class="post-metadata">

**Author:** ![liam\_cutts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/liam_cutts/32/12891_2.png) [@liam\_cutts](https://discourse.codecombat.com/u/liam_cutts)\
**Post date:** [June 24, 2020, 9:15am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/13 "2020-06-24T09:15:55Z")

</div>

wat do I put in this comand

---

<div class="post-metadata">

**Author:** ![liam\_cutts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/liam_cutts/32/12891_2.png) [@liam\_cutts](https://discourse.codecombat.com/u/liam_cutts)\
**Post date:** [June 24, 2020, 9:16am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/14 "2020-06-24T09:16:14Z")

</div>

```python
 hero.command(friend, "move", {"x": friend.pos.x + 5, "y": friend.pos.y})

```

---

<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 24, 2020, 9:17am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/15 "2020-06-24T09:17:51Z")

</div>

In an else to this if

> [@AnSeDra](#):
>
> `if enemy:`

Do you need any more assistance at this level?

---

<div class="post-metadata">

**Author:** ![liam\_cutts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/liam_cutts/32/12891_2.png) [@liam\_cutts](https://discourse.codecombat.com/u/liam_cutts)\
**Post date:** [June 24, 2020, 9:21am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/16 "2020-06-24T09:21:38Z")

</div>

can you show me wat it should look like I’m so confused

---

<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 24, 2020, 9:24am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/17 "2020-06-24T09:24:02Z")

</div>

```python
enemy = friend.findNearestEnemy()
if enemy:
    #command to attack
else:
    #command to move

```

Do you need any more assistance at this level?

---

<div class="post-metadata">

**Author:** ![liam\_cutts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/liam_cutts/32/12891_2.png) [@liam\_cutts](https://discourse.codecombat.com/u/liam_cutts)\
**Post date:** [June 24, 2020, 9:26am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/18 "2020-06-24T09:26:36Z")

</div>

can you show me all of it together the code please

---

<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 24, 2020, 9:31am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/19 "2020-06-24T09:31:00Z")

</div>

Put this

> [@AnSeDra](#):
>
> ```python
> enemy = friend.findNearestEnemy()
> if enemy:
> #command to attack
> else:
> #command to move
> 
> ```

Instead of all of this( but don’t forget to command the friend)

> [@liam\_cutts](#):
>
> ```python
> hero.command(friend, "attack", enemy)
> # Command to move east by small steps.
> hero.command(friend, "move", {"x": friend.pos.x + 5, "y": friend.pos.y})
> 
> ```

Do you need any more assistance at this level?

---

<div class="post-metadata">

**Author:** ![liam\_cutts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/liam_cutts/32/12891_2.png) [@liam\_cutts](https://discourse.codecombat.com/u/liam_cutts)\
**Post date:** [June 24, 2020, 10:02am UTC](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513/20 "2020-06-24T10:02:17Z")

</div>

```python
while True:
    friends = hero.findFriends()
    # Use for-loop and for each friend:
    for friend in friends:
        enemy = friend.findNearestEnemy()
if enemy:
    hero.command(friend, "attack", enemy)
    # Command to move east by small steps.
else:
    hero.command(friend, "move", {"x": friend.pos.x + 5, "y": friend.pos.y})

```

[Next page](https://discourse.codecombat.com/t/solved-stuck-on-hunting-party/22513.md?page=2)
