Prime pathing help

i have a problem in prime pathing, i was able to get the hero out of the maze, but whenever i try to get the soldiers out, it just sends them to my position, here is my code

the code
function isprime(number) {
    for (var i = 2; i <= Math.ceil(Math.sqrt(number)); i++) {
        if (number % i === 0) {
            return false;
    return true;
var mines = hero.findHazards();
var safemines = [];
var steps = 0;
var inc = true;
for (var i = 0; i < mines.length; i++) {
    var mine = mines[i];
    if (isprime(mine.value)) {
var movements = [];
while (true) {
    var movement = null;
    var mine = hero.findNearest(safemines);
    if (mine) {
    var greenflag = hero.findFlag("green");
    if (greenflag) {
    var blackflag = hero.findFlag("black");
    if (blackflag) {
    var friends = hero.findFriends();
    for (var i = 0; i < friends.length; i++) {
        var friend = friends[i];
        if (movements.length > (i + 1) * 2) {
            movement = movements[(steps - i * 2)];
            hero.say(steps - i * 2);
            hero.command(friend, "move", movement);
            if (inc) {
                inc = false;
    inc = true;

as you can see, i am trying to store my hero position when i put a black flag, so that i can move my soldiers after me, each soldier will move after the other soldier has moved 5 movements, but it is not working, the array is always filled with my current hero pos, so it doesn’t store the previous movements as i am trying to do, anyone can help???

1 Like

Try making the hero wait for the soldiers so they can pass. Because what seems to happening, based on your description, is that you move forward, soldiers follow, but before they reach where you are, you moved forward again, and recommanded them. So the soldiers never reached where they were supposed to go before you started moving to the next mine, which is why they get bombed up (since they were taking shortcuts)

Basically, you need to wait for all of your allies to reach your position before you move on, or they will take a shortcut through the mines (because you commanded them again after you passed the next layer, which overrides your last command) and get killed.

Your code is pretty nice. Some comments describing what the variable movement and movements are would be great. It took me a while to figure out what those variables meant, so it would help the others who are looking at this code if you edit your post and put in some comments.

What to do: Simply make your hero wait until all your troops caught up to you.

Hope this helps! :slight_smile:

1 Like

Thanks for your help, i already figured it out, but i’ve forgotten to check the replies in her.

i solved it basically by waiting for my soldiers, and i found something super wired, when i command the soldiers to go somewhere, they don’t go exactly there, so there is like a 0.4 difference or something, so i just made a function that checks if the soldier is nearly at the point, and i made a while loop saying move until the soldier finally is there(i found out that even if the condition of the while loop will be false at some point of time, the compiler still thinks it’s an infinite loop, so i added the say move command) and it worked perfectly.

1 Like

But I still need help

1 Like

You’re posting in two topics neither of which have had any activity for 3 years. Please try to just post in one at a time.

We’re happy to help you solve problems. Post the code that you’ve written so far and folk will give suggestions on what to do next.

Instructions on how to format the code are at [Essentials] How To Post/Format Your Code Correctly.



send u r code


Please don’t ask for someone else’s code.

We’re happy to help you with problems if you’ve written your own code and it isn’t working.



1 Like