# Zoo keeper, I didn't sign up for the job!

**URL:** <https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281>\
**Category:** Level Help\
**Created:** [September 1, 2021, 2:41am UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281 "2021-09-01T02:41:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellodaddy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellodaddy/32/30448_2.png) [@hellodaddy](https://discourse.codecombat.com/u/hellodaddy)\
**Post date:** [September 1, 2021, 2:41am UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281/1 "2021-09-01T02:41:27Z")

</div>

This is my code

```python
points = [{"x": 33, "y": 42},
          {"x": 47, "y": 42},
          {"x": 33, "y": 26},
          {"x": 47, "y": 26}]

while True:
    item = hero.findNearestItem()
    if item and hero.gold < 80:
        hero.move(item.pos)
    elif hero.gold >= 80:
        hero.moveXY(40, 25)
for i in range(4):
    hero.summon("soldier")
    
while True:
    friends = hero.findFriends()
    for j in range(len(friends)):
        point = points[j]
        friend = friends[j]
        enemy = friend.findNearestEnemy()
        if enemy and enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
            
            hero.command(friend, "attack", target)
            pass
            
        else:
            
            hero.command(friend, point, enemy)
            pass
            
            

```

---

<div class="post-metadata">

**Author:** ![Alfa\_Jayden\_Iskandar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/alfa_jayden_iskandar/32/23714_2.png) [@Alfa\_Jayden\_Iskandar](https://discourse.codecombat.com/u/Alfa_Jayden_Iskandar)\
**Post date:** [September 1, 2021, 4:17am UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281/2 "2021-09-01T04:17:46Z")

</div>

you dont have a break in the first while true i think so it wont go out

---

<div class="post-metadata">

**Author:** ![hellodaddy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellodaddy/32/30448_2.png) [@hellodaddy](https://discourse.codecombat.com/u/hellodaddy)\
**Post date:** [September 1, 2021, 6:32pm UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281/3 "2021-09-01T18:32:22Z")

</div>

Oh, thanks, I will see if that works.

---

<div class="post-metadata">

**Author:** ![hellodaddy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellodaddy/32/30448_2.png) [@hellodaddy](https://discourse.codecombat.com/u/hellodaddy)\
**Post date:** [September 1, 2021, 6:36pm UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281/4 "2021-09-01T18:36:30Z")

</div>

That helped. And I summon soldiers now, but I don’t command them. Since for-loops are like while loops I tried to is break, but it only summoned one soldier, What if statment could help with that?

```python
for i in range(4):
    hero.summon("soldier")
    if blahblahblah:
        break  

```

---

<div class="post-metadata">

**Author:** ![hellodaddy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellodaddy/32/30448_2.png) [@hellodaddy](https://discourse.codecombat.com/u/hellodaddy)\
**Post date:** [September 1, 2021, 6:37pm UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281/5 "2021-09-01T18:37:36Z")

</div>

I wish there was soldier.amount, then I could do  
If soldier.amount == 4:  
break.

---

<div class="post-metadata">

**Author:** ![hellodaddy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellodaddy/32/30448_2.png) [@hellodaddy](https://discourse.codecombat.com/u/hellodaddy)\
**Post date:** [September 1, 2021, 6:45pm UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281/6 "2021-09-01T18:45:22Z")

</div>

My problem is in here now,

```python
while True:
    friends = hero.findFriends()
    for j in range(len(friends)):
        point = points[j]
        friend = friends[j]
        enemy = friend.findNearestEnemy()
        if enemy and enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
            hero.command(friend, "attack", enemy)
            pass
            
        else:
            hero.command(friend, "move", points[].pos)
            pass
            

```

---

<div class="post-metadata">

**Author:** ![CryptiCrystal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/crypticrystal/32/16228_2.png) [@CryptiCrystal](https://discourse.codecombat.com/u/CryptiCrystal)\
**Post date:** [September 1, 2021, 6:52pm UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281/7 "2021-09-01T18:52:03Z")

</div>

> [@hellodaddy](#):
>
> `hero.command(friend, "move", points[].pos)`

this should just be `hero.command(friend, "move", point)`

---

<div class="post-metadata">

**Author:** ![hellodaddy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellodaddy/32/30448_2.png) [@hellodaddy](https://discourse.codecombat.com/u/hellodaddy)\
**Post date:** [September 1, 2021, 6:53pm UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281/8 "2021-09-01T18:53:38Z")

</div>

I tried that, didn’t work.

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [September 1, 2021, 6:54pm UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281/9 "2021-09-01T18:54:01Z")

</div>

> [@hellodaddy](#):
>
> ```python
> if blahblahblah:
> break  
> 
> ```

You don’t need the if statement or the break.

> [@hellodaddy](#):
>
> `hero.command(friend, "move", points[].pos)`

That should be `hero.command(friend, "move", point)` (if you define point as points[j]) or `hero.command(friend, "move", points[j])`

---

<div class="post-metadata">

**Author:** ![hellodaddy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellodaddy/32/30448_2.png) [@hellodaddy](https://discourse.codecombat.com/u/hellodaddy)\
**Post date:** [September 1, 2021, 6:55pm UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281/10 "2021-09-01T18:55:00Z")

</div>

Thank you, abc, that worked!

---

<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:** [September 2, 2021, 6:55am UTC](https://discourse.codecombat.com/t/zoo-keeper-i-didnt-sign-up-for-the-job/30281/11 "2021-09-02T06:55:26Z")

</div>

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