[SOLVED] Noble sacrifice help please

Can you show me your code?

Andrei

# Collect 80 gold
while hero.gold < 80:
    item = hero.findNearestItem()
    hero.moveXY(item.pos.x, item.pos.y)
# Build 4 soldiers to use as bait
for i in range(4):
    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
for i in range(len(soldiers)):
    hero.command(soldiers[i], "move", points[i])

Soldiers is undefined because you haven’t defined it. You’ve defined friends but not soldiers.
Danny

2 Likes

1 Like

And still you haven’t done everyting that I told you to do.

Andrei

i finished the level! :partying_face: thanks @AnSeDra and @Deadpool198

1 Like

1 Like

No problem! And congratulations for completing the level and the bonus! :partying_face:

1 Like

im stuck (20 characters)

never mind i got it…

1 Like

next time you are stuck make sure to post your code correctly by pressing the </> button.

i need help with noble sacrifice

Collect 80 gold

while True:
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

hero.command(friend, “point”, [j])Preformatted text

i need help with noble sacrifice

Collect 80 gold

while True:
hero.findNearestItem()
if item:
hero.move(item.pos)

Build 4 soldiers to use as bait.

for j in range(4):
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

hero.command(friend, “point”, [j])

As do I,

while hero.gold < 80:
    item = hero.findNearestItem()
    hero.move(item.pos)
# Build 4 soldiers to use as bait
for i in range(4):
    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
for i in range(len(soldiers)):
    #here make soldier soldiers[i]
    #here make pos points[i]
    hero.command(soldier, "move", pos)

while hero.gold < 80:
    item = hero.findNearestItem()
    hero.move(item.pos)
# Build 4 soldiers to use as bait
for i in range(4):
    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 }
soldiers = hero.findFriends()
# Use range to make an array to loop over.
# Match the friends to the points and command them to move
for soldier in soldiers:
    for pos in points:
        #here make soldier soldiers[i]
        #here make pos points[i]
        hero.command(soldier, "move", pos)

my soldiers move to the point closest to the yeti, all of them, and then they don’t move back along the other points… I don’t know why they do this… Please help…

You’re telling each soldier to move to each point. for soldier in soldier operates on each soldier individually. For that single soldier, you’re commanding it to move to each point in points. Instead, try dealing with both in the same loop, instead of nesting the loops. This should be pretty easy because the length of the soldiers array and the length of the points array are the same.

1 Like