bitburner-official / bitburner-src

Bitburner source code.
Other
759 stars 251 forks source link

[Feature request] Option to disable the restriction of ns instances being unmodifiable. #507

Closed jjayeon closed 1 year ago

jjayeon commented 1 year ago

(Bitburner v2.2.2)

Title is pretty self-explanatory, is it possible to have some kind of hidden, secret option to allow the ns instance passed to main to be modifiable? I have a large amount of legacy scripts that uses ns.jjy as a namespace for importing libraries. I don't remember exactly why I did it that way, but I probably had a good reason.

I understand that this was probably added to prevent new players/less experienced coders from somehow breaking the game in unexpected ways, so this option can be well-hidden in the options and come with a nice, big warning not to activate unless you REALLY know what you're doing.

I'll include a link to my code as well for the curious. https://github.com/jjayeon/bitburner-dump

d0sboots commented 1 year ago

Because all your code lives inside the ns.jjy sub-object, it's actually pretty easy to mechanically fix your whole codebase with search-and-replace. Replace ns.jjy with jjy, and then replace (ns, with (ns, jjy, and (ns) with (ns, jjy) (in that order) to fix all functions and callsites.

Other than that, you only have to manually fix up main functions (to declare jjy instead of taking it as a param).

Most editors have a way to apply search-and-replace across all files at once.

bezrodnov commented 1 year ago

Can we close this ticket? Modifying ns does not make much sense, it's not safe and is a totally unnecessary option.

jjayeon commented 1 year ago

thanks for the tip! will do this instead