# Help! Im stuck on zoo keeper

**URL:** <https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564>\
**Category:** Uncategorized\
**Created:** [January 24, 2016, 1:10am UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564 "2016-01-24T01:10:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![junglywood](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/junglywood/32/3643_2.png) [@junglywood](https://discourse.codecombat.com/u/junglywood)\
**Post date:** [January 24, 2016, 1:10am UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/1 "2016-01-24T01:10:25Z")

</div>

help im stuck on this level! this is my code

points = []  
points[0] = {“x”: 33, “y”: 42}  
points[1] = {“x”: 47, “y”: 42}  
points[2] = {“x”: 33, “y”: 26}  
points[3] = {“x”: 47, “y”: 26}  
while self.gold \<=80:  
coin = self.findNearest(self.findItems())  
if coin:  
self.move(coin.pos)  
for i in range(4):  
self.summon(“soldier”)  
loop:  
friends = self.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:  
self.command(friend, “attack”, enemy)  
if friend:  
self.command(friend, “move”, point)

---

<div class="post-metadata">

**Author:** ![junglywood](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/junglywood/32/3643_2.png) [@junglywood](https://discourse.codecombat.com/u/junglywood)\
**Post date:** [January 24, 2016, 1:11am UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/2 "2016-01-24T01:11:25Z")

</div>

does anyone know whats wrong with it?

---

<div class="post-metadata">

**Author:** ![junglywood](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/junglywood/32/3643_2.png) [@junglywood](https://discourse.codecombat.com/u/junglywood)\
**Post date:** [January 24, 2016, 1:15am UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/3 "2016-01-24T01:15:09Z")

</div>

my friends dont attack the ogres and im not sure what the problem is.

---

<div class="post-metadata">

**Author:** ![zuf](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/zuf/32/34897_2.png) [@zuf](https://discourse.codecombat.com/u/zuf)\
**Post date:** [January 24, 2016, 1:26am UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/4 "2016-01-24T01:26:59Z")

</div>

Maybe the `if friend:` cancels out the “attack” command above it, but it’s hard to be sure since the code isn’t formatted properly.

Please format your code properly by putting the proper back ticks or using the preformated text button. It’s explained in the FAQ that everyone should read “before posting.”

> [@FAQ - Check Before Posting](https://discourse.codecombat.com/t/faq-check-before-posting/1027#code-help):
>
> Check This Awesome FAQ Before Posting … you know it’s sweet stuff! Might save your life some day. [I need help with my code!](#code-help) Check each level’s help guide for common tips If a level is too hard, try a different hero or different items Common error messages and how to debug them Post your code with radiant, harmonious formatting Personal coding help from the CodeCombat staff [The game is not working!](#not-working) It crashes It doesn’t load It’s slow The graphics aren’t showing up [Can you please fix …](#bugs)

---

<div class="post-metadata">

**Author:** ![Steven\_Kang2003](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Steven\_Kang2003](https://discourse.codecombat.com/u/Steven_Kang2003)\
**Post date:** [January 24, 2016, 5:15am UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/5 "2016-01-24T05:15:10Z")

</div>

Y U NO FORMAT  
 ![](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex016/uploads/codecombat/original/2X/8/80b6bf463c06c17020a581a1020e6e0822563eff.jpg)

---

<div class="post-metadata">

**Author:** ![Thelightside](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@Thelightside](https://discourse.codecombat.com/u/Thelightside)\
**Post date:** [January 24, 2016, 4:47pm UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/6 "2016-01-24T16:47:47Z")

</div>

Please format correctly by looking at the FAQ.

---

<div class="post-metadata">

**Author:** ![AdrianCgw](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@AdrianCgw](https://discourse.codecombat.com/u/AdrianCgw)\
**Post date:** [January 25, 2016, 1:35am UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/7 "2016-01-25T01:35:10Z")

</div>

If you give two successive orders to a unit in the same loop cycle (or without letting time pass)  
the second order will override the first:  
command(attack) + command(move) = command(move)

See:

> [@Zoo Keeper Help!(Python)](https://discourse.codecombat.com/t/zoo-keeper-help-python/6480/12):
>
> Try this: for j in range(len(friends)): point = points[j] friend = friends[j] enemy = friend.findNearestEnemy() if friend and enemy and enemy.team == "ogres" and friend.distanceTo(enemy) \< 5: self.command(friend, "attack", enemy) elif friend: self.command(friend, "move", point) Shortly, this way of codding is bad: if something attack if something\_else move This is good: if something attack elif something\_else …

---

<div class="post-metadata">

**Author:** ![junglywood](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/junglywood/32/3643_2.png) [@junglywood](https://discourse.codecombat.com/u/junglywood)\
**Post date:** [January 26, 2016, 1:28am UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/8 "2016-01-26T01:28:50Z")

</div>

thanks! It worked!!😁

---

<div class="post-metadata">

**Author:** ![Sirtrumpet](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sirtrumpet/32/9060_2.png) [@Sirtrumpet](https://discourse.codecombat.com/u/Sirtrumpet)\
**Post date:** [December 9, 2018, 1:48pm UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/9 "2018-12-09T13:48:39Z")

</div>

My code doesn’t work. My hero just walks away for about 3 second and than summons the soldiers and doesn’t collect gold first.

```python
points = []
points[0] = {"x": 33, "y": 42}
points[1] = {"x": 47, "y": 42}
points[2] = {"x": 33, "y": 26}
points[3] = {"x": 47, "y": 26}
item = hero.findNearestItem()
# 1. Collect 80 gold.
for i in range(80):
    hero.move(item.pos)
# 2. Build 4 soldiers.
for i in range(4):
    hero.summon("soldier")
    
# 3. Send your soldiers into position.
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:
            # Command friend to attack.
            hero.command(friend, "attack", enemy)
            pass
            
        elif friend:
            # Command friend to move to point.
            hero.command(friend, "move", point)
            pass
            
            

```

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [December 9, 2018, 2:29pm UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/10 "2018-12-09T14:29:05Z")

</div>

Hi, the problem is that your hero’s only able to move towards one item, because you’ve only defined on item.  
And since move takes practically no time he’ll only move towards it properly when move’s looped.  
You should try and use something like:  
while hero.gold …  
but remember to define the item inside the loop.  
🦁 🦁 🦁

---

<div class="post-metadata">

**Author:** ![Sirtrumpet](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sirtrumpet/32/9060_2.png) [@Sirtrumpet](https://discourse.codecombat.com/u/Sirtrumpet)\
**Post date:** [December 15, 2018, 10:45pm UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/11 "2018-12-15T22:45:15Z")

</div>

Thank you so much I was stuck for weeks.

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [December 16, 2018, 1:57pm UTC](https://discourse.codecombat.com/t/help-im-stuck-on-zoo-keeper/6564/12 "2018-12-16T13:57:42Z")

</div>

My pleasure 😁,  
🦁
