I tried to loop so the soldiers would lure Mr. Yeti but it won’t work.
# Collect 80 gold
while hero.gold <= 80:
coin = hero.findNearestItem()
if coin:
hero.move(coin.pos)
soldiers = 0
while soldiers < 4:
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
soldiers += 1
# Send your soldiers into position
points = []
points[0] = { "x": 13, "y": 73 }
points[1] = { "x": 51, "y": 73 }
points[2] = { "x": 51, "y": 53 }
points[3] = { "x": 90, "y": 52 }
friends = hero.findFriends()
# Use range to make an array to loop over.
while True:
for j in range(len(friends)):
point = points[j]
friend = friends[j]
if friend:
hero.command(friend, "move", point)
Never mind, I figured it out
I did something
My hero does nothing when I run this code.
item = hero.findNearestItem()
while hero.gold < 80:
hero.move(item.pos)
# Build 4 soldiers to use as bait
self.summon("soldier")
self.summon("soldier")
self.summon("soldier")
self.summon("soldier")
# Send your soldiers into position
soldier = hero.findFriends()
points = []
points[0] = { "x": 13, "y": 73 }
points[1] = { "x": 51, "y": 73 }
points[2] = { "x": 51, "y": 53 }
points[3] = { "x": 90, "y": 52 }
friends = hero.findFriends()
hero.command(soldier[0], "move", point[0])
hero.command(soldier[1], "move", point[1])
hero.command(soldier[2], "move", point[2])
hero.command(soldier[3], "move", point[3])
# Use range to make an array to loop over.
# Match the friends to the points and command them to move
help please.
That’s because ‘soldier ’ is not defined. Instead, you should loop through your ‘friends’ array, assigning them to their specific points. That’s what the comments are telling you:
# Use range to make an array to loop over.
# Match the friends to the points and command them to move
1 Like
You’ve defined all the positions as points and then tasked the soldiers to move to point.
1 Like
What @jka2706 is trying to say is that you are using point as an array, but the array you should use is points.
Here try to put
soldiers = hero.findFriends()
Andrei
still not working can you explain more.
item = hero.findNearestItem()
while hero.gold < 80:
hero.move(item.pos)
# Build 4 soldiers to use as bait
self.summon("soldier")
self.summon("soldier")
self.summon("soldier")
self.summon("soldier")
# Send your soldiers into position
soldier = hero.findFriends()
points = []
points[0] = { "x": 13, "y": 73 }
points[1] = { "x": 51, "y": 73 }
points[2] = { "x": 51, "y": 53 }
points[3] = { "x": 90, "y": 52 }
soldiers = hero.findFriends()
hero.command(soldier[0], "move", point[0])
hero.command(soldier[1], "move", point[1])
hero.command(soldier[2], "move", point[2])
hero.command(soldier[3], "move", point[3])
# Use range to make an array to loop over.
# Match the friends to the points and command them to move
fredandgeorge:
hero.command(soldier[0], "move", point[0])
hero.command(soldier[1], "move", point[1])
hero.command(soldier[2], "move", point[2])
hero.command(soldier[3], "move", point[3])
Here you have to use the array points instead of
using point .
Andrei
TEO
August 28, 2020, 2:38am
9
Hi everyone i was just stuck on this lvl i build the soldiers start moving and then an error comes up look.
# Collect 80 gold
while hero.gold< 80:
item = hero.findNearestItem()
hero.move(item.pos)
# Build 4 soldiers to use as bait
hero.summon("soldier")
hero.summon("soldier")
hero.summon("soldier")
hero.summon("soldier")
# Send your soldiers into position
points = []
points[0] = { "x": 13, "y": 73 }
points[1] = { "x": 51, "y": 73 }
points[2] = { "x": 51, "y": 53 }
points[3] = { "x": 90, "y": 52 }
friends = hero.findFriends()
# Use range to make an array to loop over.
# Match the friends to the points and command them to move
if friends:
hero.command(friend, "move", points)
and this is the error
weary
August 28, 2020, 3:28am
10
You have to put for loop around the friends.
TEO
August 28, 2020, 3:28am
11
i already solved it but thx anyway