Help! Im stuck on zoo keeper


#1

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)


#2

does anyone know whats wrong with it?


#3

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


#4

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."


#5

Y U NO FORMAT


#6

Please format correctly by looking at the FAQ.


#7

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:


#8

thanks! It worked!!:grin: