Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Desert basin stampede javascript

hello, in desert “basin stampede” even when code is wrong, once hero stops if you have enough hp the yaks push you to the oasis and you successfully complete. can i have any hints with code please? ^^ tried various things

also - what is “accessing properties” refering to?
my code (i edited a bit to not be absolute obvious)

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

about var yPos-> shouldnt it be outside the loop, so that the player begins from y=17 but once loop starts it needs to be constantly changing…
btw-im not sure but I saw some people writing its not allowed to post full code, if so - how should i post it? i cant show only parts of it since i dont know where exactly the problem is…
sorry for all the noobish questions ^^"

Hi Ksensei,

Well done on completing the level - yes sometimes I’ve completed even with ‘wrong’ code; I think just small bugs (or maybe look at it that that’s like real life - sometimes things go right even when they shouldn’t really - and sometimes you have the right code but the wrong armour, or are just unlucky with the starting seed). Sometimes I go back and work through the problems to learn more, and sometimes I just accept it.

moveXY needs 2 numbers in the brackets to work, which is the error that is showing.

I’m not quite sure about the answer to your question about accessing properties, I’ll leave it to someone else to answer.

With the var yPos inside the loop, I think it means that your hero will come back to that y pos on each loop, and can then move +/- 3 from it. If you put the starting y pos outside the loop then the hero would be able to move much further - possibly off the screen. It depends what you want to happpen.

Re code - CoCo asks that answers aren’t posted, so that other people have to work things out rather than just copy and pasting someone else’s; but there seems to be a level of reasonableness about this. If your code sort of works but you have questions about it, then maybe keep it up for a few days while folk look at it to answer your questions, and then edit your post to take it down?

No need to apologise for asking questions - questions are good :smile:.


thx for reply ^^ i always move forward and back to whatever i can, but i really want to understand why something isnt working…
i tried various things with

 hero.moveXY(xPos, yPos);

(i know its marking it in the screenshot but you see in the code i posted its with parameters)
although if im not the only one maybe it really is a bug in the spesific level, ill wait for more replies ^^

Think of the behavior as more of an exploit, rather than a bug. There are several levels throughout the campaigns where brute force will succeed, even when the code won’t. The goal is to figure out a method to solve the level…preferably with proper coding, but this is not implicitly stated. Therefore, even though you passed (good job btw!), the challenge, should you choose to accept it, is to figure out what’s wrong with your code (which includes asking for help if needed) and fix it.

There is nothing wrong with posting all of your code, if you are needing help. Sometimes this is even required, as the issue could be in one place, but shows up in another. There is also nothing wrong with only posting the problem block of code…it all depends on the particular piece being worked on. As jka mentions, you can always edit your posts if you feel the need…replacing the entire code with just the problem line of code is not a bad idea.

“Accessing Properties”. Properties and attributes…they are members of an ‘object’. Something that defines, or describes, an object. This level gives a very basic look at the ‘.pos’ property. Take this line as an example:

var xPos = hero.pos.x + 5;

xPos is the variable being defined. It is defined as hero.pos.x + 5. ‘hero’ is the object, ‘.pos’ is the property and ‘.x’ is the attribute…’.pos’, the property, actually has other attributes, such as ‘.y’ too. In coming levels this will be explored a bit deeper…


Now, to the meat of the problem. You define yPos as = 17:

       var yPos = 17;

But, you never redefine it…yPos is always going to equal 17. Instead of moving inside your ‘if block’, try simply redefining yPos instead. Your final statement is the only ‘move’ command needed.

All I did is stand there and let the yaks push me to the oasis

i started doing the desert from beginning to see what ive been missing cause am starting to get confused on advanced stages and i happenned to solve this one with simply adding

    else {
    hero.moveXY(xPos, yPos);

at the bottom line before the hero.move!
works perfect now

BUT at submit (at first run it worked) it didnt work and hero stops on spot, for the same code
i think there IS a bug in this stage, its inconsistent