[SOLVED]HELP ME with Prime Pathing


#1

In the Level Prime Pathing after my hero reached the end point and start to command my friends, their just getting to the last point I command them to while ignoring the other point. I can’t figure what I am doing wrong :confused:

var safe = [];
var phase = 0;
var fphase = 0;
var start = 0;
var count = 0;
function isPrime(trap) {
    var start = 2;
    while (start <= Math.sqrt(trap.value)) {
        if (trap.value % start++ < 1)
            return false;
    }
    return true;
}
function findf(f) {
    var friend = null;
    var friends = hero.findFriends();
    friend = friends[f];
    return friend;
}
var mines = hero.findHazards();
for (var i = 0; i < mines.length; i++) {
    var mine = mines[i];
    if (mine && mine.pos.x < 80 && isPrime(mine)) {
        safe.push(mine);
    }
}
while (true) {
    if (phase === 0) {
        var target = hero.findNearest(safe);
        if (target) {
            hero.moveXY(hero.pos.x, target.pos.y);
            hero.moveXY(target.pos.x, target.pos.y);
            hero.moveXY(target.pos.x - 12, target.pos.y);
        }
        if (hero.pos.x < 20 && hero.pos.y > 30) {
            hero.moveXY(5, 13);
            phase++;
        }
    }
    if (phase === 1) {
        var target = hero.findNearest(safe);
        if (target) {
            hero.moveXY(hero.pos.x, target.pos.y);
            hero.moveXY(target.pos.x, target.pos.y);
            hero.moveXY(target.pos.x + 12, target.pos.y);
        }
        if (hero.pos.x > 80) {
            hero.moveXY(97, 9);
            phase++;
        }
    }
    if (phase > 1) {
        var friends = findf(fphase);
        var mine = friend.findNearest(safe);
        var walker = friend;
        if (start < 1) {
            hero.command(walker, "move", {
                "x": mine.pos.x + 5,
                "y": mine.pos.y
            });
            hero.command(walker, "move", {
                "x": mine.pos.x,
                "y": mine.pos.y
            });
            hero.command(walker, "move", {
                "x": mine.pos.x - 13,
                "y": mine.pos.y
            });
        }
        if (walker.pos.x < 20 && walker.pos.y > 30) {
            hero.command(walker, "move", {
                x: 5,
                y: 13
            });
            start++;
        }
        if (start === 1) {
            hero.command(walker, "move", {
                "x": mine.pos.x - 5,
                "y": mine.pos.y
            });
            hero.command(walker, "move", {
                "x": mine.pos.x,
                "y": mine.pos.y
            });
            hero.command(walker, "move", {
                "x": mine.pos.x + 13,
                "y": mine.pos.y
            });
        }
        if (walker.pos.x > 80) {
            hero.command(walker, "move", {
                x: 97,
                y: 9
            });
            start = 0;
            fphase++;
        }
    }
}


EDIT: I solved it by splitting the commands into an if and else phrase