bitburner-official / typescript-template

Starter repo for players who want to write bitburner scripts in typescript.
53 stars 98 forks source link

Something weird about Bitburner's scripting language that I've always been wondering about. #22

Open seannaquah opened 2 days ago

seannaquah commented 2 days ago

Why does Increment and Decrement get implemented as ++i; and --i; instead of the usual i++; and i--; that all languages use? For example, normally if I want to single increment i, i do i++; , and if i was to single decrement i, i do i--; . If I want to increment i by n, i do i+=n; , and if i want to decrement i by n, i do i-=n; . Or I could do it the longer way and do i = i + n; to increment i by n, and i = i - n; to decrement i by n.

The other thing is the script editor. It forces me to use the arrow keys to bypass the brackets and quotes, etc. once I've filled them out instead of letting me just hit Tab or something to skip to the end outside the bracketing, so that I can continue scripting smoothly and quickly. I never had this kind of problems in C, C++, C#, Java, Basic, or even PLC (Programmable Logic Control) programming for Engineering (it works kind of like Assembly Language), etc. or even old languages like LISP (though I have to admit that LISP if you don't use the right editor is a pain in the ass), Prolog, Pascal, Perl, etc. editors or IDEs. Or even scripting languages like JavaScript, markup languages like HTML, XHTML, XML, etc.

And that's just the beginning of scripting and programming. We're not even talking about classes and methods, constructors and destructors, etc. yet. The most frustrating thing is that I can't seem to find the API reference for Bitburner for the main scripting capabilities and the commands, statements, etc. and had to go look it up in W3Schools. And that just tells me ALL the JavaScript stuff, and not what is available in Bitburner which I can use. Basically, there's no in-game API reference.

Hoekstraa commented 2 days ago

Hi there!

Why does Increment and Decrement get implemented as ++i; and --i; instead of the usual i++; and i--; that all languages use? For example, normally if I want to single increment i, i do i++; , and if i was to single decrement i, i do i--; . If I want to increment i by n, i do i+=n; , and if i want to decrement i by n, i do i-=n; . Or I could do it the longer way and do i = i + n; to increment i by n, and i = i - n; to decrement i by n.

Bitburner uses Javascript. So let's have a look at Mozilla's Javascript documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Increment. You can see that both are possible, i++ and ++i. This is the same as with C, C++, C#, Java.. and a bunch of other languages. The difference between these two is: let i = 1; const inc = i++; ns.print(inc) returns 1 let i = 1; const inc = ++i; ns.print(inc) returns 2

So when you put the ++ in front, you can think of it as "I'm incrementing it first and then returning the value of i", while if you put the ++ behind, you return the value first, and then increment the number.

The other thing is the script editor. It forces me to use the arrow keys to bypass the brackets and quotes, etc. once I've filled them out instead of letting me just hit Tab or something to skip to the end outside the bracketing, so that I can continue scripting smoothly and quickly. I never had this kind of problems in C, C++, C#, Java, Basic, or even PLC (Programmable Logic Control) programming for Engineering (it works kind of like Assembly Language), etc. or even old languages like LISP (though I have to admit that LISP if you don't use the right editor is a pain in the ass), Prolog, Pascal, Perl, etc. editors or IDEs. Or even scripting languages like JavaScript, markup languages like HTML, XHTML, XML, etc.

I never liked the editor much, which is exactly why I made a tool (and protocol etc.) for Bitburner so you can use your own texteditor/IDE. I'd recommend you ask about this in the Discord (https://discord.gg/TFc3hKD). There's a channel for it called #external-editors. If you're going here, tell the nice folks over there Zonoia says hi!

And that's just the beginning of scripting and programming. We're not even talking about classes and methods, constructors and destructors, etc. yet. The most frustrating thing is that I can't seem to find the API reference for Bitburner for the main scripting capabilities and the commands, statements, etc. and had to go look it up in W3Schools. And that just tells me ALL the JavaScript stuff, and not what is available in Bitburner which I can use. Basically, there's no in-game API reference.

You can find the API reference here: https://github.com/bitburner-official/bitburner-src/blob/dev/markdown/bitburner.ns.md It should be linked to from within the Bitburner code editor.

For more info on the game, I'd really urge you to check out the Discord. This is where all the smart and cool people hang out. It really is the place to ask questions like these :)