hi Guys i’m not sure if it’s a bug or i did a mistake so here is my code
# Move forward to reach the oasis,
# but move back to avoid nearby yaks.
loop:
enemy = self.findNearestEnemy()
if enemy and self.distanceTo(enemy) < 10:
# Move to the left by subtracting 10 from your X coordinate.
pass
x = self.pos.x -10
y = self.pos.y
self.moveXY(x, y)
else:
x = self.pos.x +10
y = self.pos.y
self.moveXY(x, y)
# Move to the right by addding 10 from your X coordinate.
pass
Do i need to use flags too or i just to focus more
ps this is the first time getting into trouble lol so please if it’s not a bug don’t post the answer and let me figure it by my self , ty
Edit : I’m using Tharin
I’m pretty confused, because my code is equivalent to yours, but the yaks don’t get me. Can you double-check how much speed you have and let me know? Also, a screenshot of the moment where the yak first gets you would help.
i remember that level i had to get creative to beat it. i had the same problem with the yak hitting me.
I just rechecked it and my speed changed again i guess because it was failing. got it working again for my speed.
// Move forward to reach the oasis,
// but move back to avoid nearby yaks.
loop {
enemy = this.findNearest(this.findEnemies());
if (enemy && this.distanceTo(enemy) < 20) {
// Move to the left by subtracting 10 from your X coordinate.
x = this.pos.x - 4;
} else {
// Move to the right by addding 10 from your X coordinate.
x = this.pos.x + 4;
}
this.moveXY(x, this.pos.y);
}
Yep. each hero has a speed but also they can get different boots that further changes that. so this is a pretty tricky level to make work for everybody.
I just switched the yak timing a little bit and I think I fixed the problem; please try again with distances of 10 and let me know if you are still seeing any problems. Thanks!
I could not figure out what was wrong with my code. Turns out it was just being short-sighted and trying to move too far before checking distance to yaks. I got it working with move distances of 4 and a viewing distance of 20. update: optimal seems to be move dist of 5 and view dist of 10. I’m using Anya with softened leather boots.
It’s the comments that encourage ‘rigid thinking’ with a stated fixed distance of 10. Maybe just sub in ‘a certain distance’ (experiment!) instead of specific measurements?
Also I had to add an extra ‘else’ block because the yaks eventually stop moving and so there are no enemies left to spur movement.
Hmm, it’s supposed to work with 10m movement. You say that you were trying to move too far–the yaks were getting you before you had time to run, or you ran backwards into a yak…?
I did a silly hack…if I used an alert (in the JS version this.say("any message here)) at the beginning of my loop, I survived. Otherwise I died on the first movement. So I “succeeded,” but…meh.
Looks like it didn’t quite work for your particular speed, so I tweaked it a bit and it should be working for that speed as well, now, too. Sorry about that!