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.