Basin Stampede POSSIBLE BUG?!?!?


#1
// Keep moving right, but adjust up and down as you go.

while(true) {
    var enemy = hero.findNearestEnemy();
    var x = hero.pos.x + 5;
    var y = 17;
    if(enemy) {
        // Adjust y up or down to get away from yaks.
        if(enemy.pos.y > hero.pos.y) {
            // If the Yak is above you, subtract 3 from yPos.
            hero.moveXY(x, y - 3);
        } else if (enemy.pos.y < hero.pos.y) {
            // If the Yak is below you, add 3 to yPos.
            hero.moveXY(x, y + 3);
        }
    }
    hero.moveXY(x, y);
}

The level tells me to do exactly what I did, and I still end up getting killed! Can someone please help me with finding out the problem?


#2

Dont move your hero by subtracting 3 because the Y variable never actually gets updated for the next iteration. You need to assign the value to the variable Y because your code only allows you to go up or down 3 at the most.


#3
// Keep moving right, but adjust up and down as you go.

while(true) {
    var enemy = hero.findNearestEnemy();
    var xPos = hero.pos.x + 5;
    var yPos = 17;
    if(enemy) {
        // Adjust y up or down to get away from yaks.
        if(enemy.pos.y > hero.pos.y) {
            // If the Yak is above you, subtract 3 from yPos.
            hero.moveXY(xPos, yPos - 3);
        } else if (enemy.pos.y < hero.pos.y) {
            // If the Yak is below you, add 3 to yPos.
            hero.moveXY(xPos, yPos + 3);
        }
    }
    hero.moveXY(xPos, yPos);
}

I did exactly what it said, and I still died


#4

Alright I see where your coming from. Yes, technically you kind of did what they are asking for except that it needs to be assigned the value instead of you adding or subtracting inside of the moveXY function. They did say // If the Yak is above you, subtract 3 from yPos.. You did add/ subtract 3 from yPos but they want you to keep the value so you can keep going farther than yPos = 14 or 20.

while(true) {
    var enemy = hero.findNearestEnemy();
    var xPos = hero.pos.x + 5;   <-- #This is what they are really asking for.
    var yPos = 17;                   #Except that they want you to change yPos in the if/else part.

What they really want you to do is to reassign var yPos with + or - 3. Then insert the values into the moveXY function once yPos has been reassigned.

 if(enemy.pos.y > hero.pos.y) {
            // If the Yak is above you, subtract 3 from yPos.
            hero.moveXY(xPos, yPos - 3);      #yPos does not change in value. 
        } else if (enemy.pos.y < hero.pos.y) {
            // If the Yak is below you, add 3 to yPos.
            hero.moveXY(xPos, yPos + 3);      #yPos does not change in value. 
        } #The above two steps is where you need to reasign yPos so the below statement becomes useful.
    }
    hero.moveXY(xPos, yPos);      #Their is no point to this step since you already moved from the above statments.
                                  #Actually this step takes you right back to where you started since yPos was never changed.

Hope this helps. Please ask questions if what I said doesnt make sence. :slight_smile: