Completely blocked on Noble Sacrifice level

for(i=0;1<4;i++){ // <- second part of the for loop, 1 is ALWAYS smaller than 4! 
   //...
}

:stuck_out_tongue:

1 Like

Guess it works now? :stuck_out_tongue:

hell yes ,thanks very much good sir

I am stuck and have looked for help for JavaScript but I do not know what to do now it says I might have an infinite loop. Where?

Howdy and welcome to the forum! Please post your code, properly formatted. You can learn how here: [Essentials] How To Post/Format Your Code Correctly

With that, we can have a better chance of seeing where the problem is.

while (hero.gold < 80)
var coin = hero.findNearestItem();
hero.move(coin.pos);
// Build 4 soldiers to use as bait
for (var i = 0; i < 4; i++) {
hero.summon(“soldier”);
}
var 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
};
var friends = hero.findFriends();
while (true) {
var friends = hero.findFriends();
for (var j = 0; j < friends.length; j++) {
var point = points[j];
var friend = friends[j];
var enemy = friend.findNearestEnemy();
if (enemy && enemy.team == “ogres” && friend.distanceTo(Enemy) < 5) {
hero.command(friend, “attack”, enemy);
} else {
hero.command(friend, “move”, point);
}
}
}

Let’s try that again…from the link I gave you, it says:

And then paste your code between the two … markers.

While you are working on that, I can see that you are missing the final instructions in your code:

// Use a for-loop to loop over i from 0 to 4
// Match the friends to the points and command them to move
(In the PY version, the first comment of this final block is “# Use range to make an array to loop over.”)

You don’t need the final while loop…the for loop alone will suffice. Also, you don’t want to attack anything…just move your Sacrifices to their designated spots and let the game play on.

Also, you are finding friends twice…only need to do that once.

how do i get to the format place?

You may need to click on the pictures to make them show.

# Collect 80 gold
while hero.gold < 80:
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y)
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": 53 }
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) # The code gets stuck here

Your if statement needs to be a member of the for loop…as shown, it’s the final statement of the while loop.

1 Like

Do you still have problem with the code?

I don’t think he does because he posted it a year ago. We have to remember to look at the dates they posted. But thank you for trying to help!