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

JavaScript alternate While loop syntax?

Hi!

I started over on game while logged out to practice and review. I don’t remember seeing various options for writing the While loops in JS, but I could have missed it with all of the new info on first round. However, I tried one of the other versions, as listed here on the instructions screen, and am receiving an error. Have I input it wrong based on the instructions, or are the two other examples for Python and CoffeeScript? I know the first listed method in attached picture works, as I’ve used it throughout first runs while in logged-in game.

Thanks for help. Here’s sample of code utilizing the third version of the listed possible syntax from instructions screen.

while(true,
moveRight(2);
moveDown();
)

Sorry, this was on the “Descending Further” screen

What boots are you wearing? The .moveLeft() (etc) commands only work with the lower-end boots. The high-end boots, starting with Leather, gives you .moveXY(). At Compound, you also get .move(). And of course, with Jumping/Leaping, you get .jumpTo().

The .moveXY() command is kind of a fire-and-forget method…your hero will continue moving until the specified destination is reached; no other code will be ran until this is complete.

The .move() command is like a step-at-a-time method. The idea is to place it in a loop. As that loop iterates and it reaches the move command, the hero will take a step towards the target, but any code following .move will fire in sequence. Something like this:

while distance > position:
    hero.move(position)
    doSomeMoreCodeHere()
    distance = hero.distanceTo(position)

Unless you’ve acquired a pair elsewhere, Simple boots is likely your only option, so you’ll want to stick with the basic .moveLeft() type commands.

And, to reply to your actual question…since I misunderstood it in my first reply (I left that reply, as it is valuable info, tho not pertinent to your question) :wink:

I don’t recognize those other two methods. I logged in using JS and then CS. I could get JS to work, but only with the first example; I could not get CS to work, no matter what I tried (first time I’ve ever tried CS, so not surprised).

Of course, the PY version would be:

while True:
    hero.moveLeft(2)

Thanks for getting back to me! I tried every way I could to make the bottom two listed in the initial instructions to work, but, I think someone was trying to update the instructions and accidentally submitted a partial, incomplete version.

Appreciate you checking in and telling me for the python side. Eventually, I’m going to reset my whole game and start again to learn that language, too.

(They are the basic and only boots available to the level, just to respond to your original info)

Also, @dedreous, I was going to attempt the CS language as well, but it’s supportive info is very underdeveloped at this point, and I need to familiarize myself with coding more deeply before I try to jump in and attempt any assistance with that part of the dev! But, one day, I’ll try to help out.

1 Like

i’m currently also trying to learn as i’m a newbie and i feel that i need a lot of help. may i ask you some questions if it won’t bother you? thanks

Hi Aidd and welcome to the forum! Of course you can ask, that is what we’re here for.

Welcome! Of course! This forum is full of super-helpful folks! Ask away!