Zoo Keeper Python Help


#1

My hero summons the four soldiers and they move to the points but they dont attack and the ogres then kill one and attack the crate and then the yeti is summoned also i want to summon more than four soldiers so that i have more men to defend the crate so how do i do that heres 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)

#2

When you run your code, your code will command your friends to atack an eneny that meets the requirements. However, you then check for a friend. If there is, theb that friend will move to the point, overriding the attack command. Don’t use a separate if-statement; just use an else-block.


#3

thanks i beat it next level


#4

Can You plz tell me how to do that since I am new.(Python)@lundor5


#5

See the other zookeeper thread. It discusses exactly this error:


#6

i beat it weeks ago i changed to an else after the if enemy