Re: 2 questions
By: DesotoFireflite to All on Fri Apr 08 2022 17:45:57
1. - When I use console.gotoxy(0,24); it takes me to line 22, not 24. Is this a normal thing +/- a few lines, or is it supposed to be dead accurate.
I believe these coordinates are 1-based, so the top left cell is 1,1. Even so I would only expect you to end up one row above where you intended. Not sure what's up with that.
FYI if your intention is to move to the first column of the last line in the terminal, I would recommend:
console.gotoxy(1, console.screen_rows);
This will get you there no matter what the dimensions of the terminal are. (There is also a 'screen_columns' property.)
2. - what are the { and } used for. As far as I can tell be reading up, they are only deed for condition statements. Just trying to understand.
Curly braces do a few different things in JS, but mostly they're creating a 'block' to group several statements together. If your 'if' statement only needs to do one thing, then you don't need them:
if (true) write('true');
or even:
if (true)
write('true');
If your 'if' statement needs to do multiple things, you'll want them:
if (true) {
write('true');
write('okay');
}
Otherwise the interpreter wouldn't know where the 'if' ended.
Same goes for 'for' loops and probably a couple other things. In other places, they are mandatory, like when defining a function using the 'function' keyword.
A lot more could be said on the subject, and somebody probably will, but I won't flood you with info just yet.
---
echicken
electronic chicken bbs - bbs.electronicchicken.com
---
þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.com