Feedback: Basin Stampede

Sorry if I wasn’t being clear. The code I posted worked. - However, I had to modify the code that was suggested by the game (i.e. take out the second instance of hero.moveXY that existed near the end of the loop). – The char behavior was quite eratic and on closer inspection it was because hero.moveXY is called twice.

To make it more clear, here’s the reset (i.e. fresh) code with only the lines

// Uh oh, a stampede! Use your cunning to make it to the oasis.

while(true) {
    var enemy = hero.findNearestEnemy();
    var xPos = hero.pos.x + 5;
    var yPos = 17;
    if(enemy) {
        // You only need to shift up/down 1m to dodge the yaks!
        if(enemy.pos.y > hero.pos.y) {
            // If the Yak is above you, adjust yPos downwards!
            /*mine*/hero.moveXY(xPos, yPos-1);
        } else if (enemy.pos.y < hero.pos.y) {
            // If the Yak is below you, adjust yPos upwards!
         /*mine */hero.moveXY(xPos, yPos+1);
        }
    }
    /*The offending, second instance code that I'm talking about, that's already in the code.*/ hero.moveXY(xPos, yPos); 
}

Oh, lol! Looking at it now, I finally understand what was meant to happen. “adjust yPos” just meant adjusting the variable – my extrapolation caused the problem.

Nevermind, I guess, but still sharing this in case other’s were affected, too.

2 Likes

I couldn’t pass this level just now until removing the last line of code that is automatically included

hero.moveXY(xPos, yPos)

I wish I understood this well enough to know why that line specifically made it not work? but I’m not entirely certain I would have passed without seeing @julix mention that they had removed the last ine.

1 Like

Another option is to make another if: statement for the yaks .pos.x vs players pos.x to ignore the yaks in front. That’s what worked for me cause I kept going in a up and down zigzag causing me to get hit before doing that.

1 Like

@Rick_Matulac I think it has something to do with the fact the hero keeps trying to go back to the yPos that was set to 17

1 Like

Yo, @Rick_Matulac hasn’t been active since march, so he won’t be able to read your post

Thanks @Chaboi_3000. I’m still learning all the ins and outs of this so I didn’t notice.

1 Like