Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Noble sacrifice please help JS

I am having some trouble with this code can someone please help?
// Collect 80 gold
while (true) {
var item = hero.findNearest(hero.findEnemies());
if (this.gold < 80) {
hero.move(item.pos);
} else {
break;
}
}
// Build 4 soldiers to use as bait
for (var z = 0; z < 4; z += 1) {
hero.summon(‘soldier’);
continue;
}
// Send your soldiers into position
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();
// Use a for-loop to loop over i from 0 to 4
// Match the friends to the points and command them to move
for (var i = 0; i < friends.length; i += 1) {
hero.command(friends[i], ‘move’, points[i]);
}

Please format your code correctly @H_G.

Also you have a while true loop, so the code after that will not run, you should use a while loop instead. While you gold is less than 80, you would collect the gold, this way the code after the loop will run.

okay! thanks for the reminder!

Hi H_G,

There’s a break in the while true loop, so (I think) it will work. But @abc has a point that your code would be easier to check if it was formatted!

However, I think this line is the problem:

Are you trying to find enemies??

Jenny

here is the code

I am having some trouble with this code can someone please help?
// Collect 80 gold
while (true) {
var item = hero.findNearest(hero.findEnemies());
if (this.gold < 80) {
hero.move(item.pos);
} else {
break;
}
}
// Build 4 soldiers to use as bait
for (var z = 0; z < 4; z += 1) {
hero.summon(‘soldier’);
continue;
}
// Send your soldiers into position
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();
// Use a for-loop to loop over i from 0 to 4
// Match the friends to the points and command them to move
for (var i = 0; i < friends.length; i += 1) {
hero.command(friends[i], ‘move’, points[i]);
}

i change that to enemy

It worked! thank you so much!

now can you click the check mark on the post that helped most?

I did it! Again, thank you.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.