Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Zoo Keeper help please

i have been stuck on zoo keeper for a little while now and this code dosent work

# Protect the cage.
# Put a soldier at each X.
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 <=80:
    coin = self.findNearest(self.findItems())
    if coin:
for i in range(4):

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

everything works well until the soldiers move to the X the dont attack at all

Look at this section. When will that condition stop being true? In other words, when will the soldiers stop moving? Your friend will always be there (unless he dies).
If there are two if statements and they’re both true, the one which took precedence first will keep executing it’s action and won’t let anything else take place.
Correction (credit: xython):
If there are many if statements and they all are true, only the last will be executed

1 Like

On another note, why are you using self? You used hero in all your other levels.
Perhaps you took it from somewhere else…Hmm.
If you don’t understand the concept then I’d prefer to explain it to you than for you to “cheat” your way through a vital level. (for loops are going to be coming up a lot further on in CoCo.


well all i had to do was add a break. that being said thanks Deadpool198!