Help with zoo keeper

For some reasond my soldiers just move the bottom right screen and ignores all my coding. Is it some thing to do with my code?


Here’s 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}

loop:
    item = self.findNearest(self.findItems())
    if item:
        self.move(item.pos)
        if self.gold > 80:
            for i in range(4):
                self.summon("soldier")
                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)
                    else:
                        self.command(friend, "move", point.pos)

Hi @Nubie207,

It has to be something with your code. But for us to help you, we need to understand the indentation of your code. So, you have to reply back with your code in radiant and harmonious formatting as mentioned in the FAQs. It is easily done by putting your code between & (on lines leading and lagging the code) (read FAQs). Once you do this, it should be easier to see errors (if any) in your code for anyone going through this thread.

Cheers

Hello, Nubie. Please read the FAQ prior to your next post, so that you can learn how to properly format your code. I’ve done it for you this time, but do so yourself in the future.

You have a few problems here. Firstly, you have all your code in a loop. This means that you hero will summon four soldiers whenever your gold is greater than 80. Move the code where you collect coins inside a while-loop, outside the loop, and summon friends outside the loop.

Secondly, on your last line, point is already a position, and you can not find the pos of a position. Just command your friend to move to point.

He’s right. I had this same exact problem, and that fixed it.

thank you to everyone to be so helpful and patient to me, as I am very new to this site, I am greatful that you helped me to pass this level. Thanks again.

1 Like