Bitburner ns2 script: a script to spawn any script without the 10-second delay imposed by ns.spawn()
As handy as ns.spawn()
is, the 10-second delay before it fires up the script can be annoying. However using ns.run()
isn't always an option, for example due to RAM constraints, or when you want a script to relaunch itself with the same arguments but a different number of threads.
Which is why I made this incredibly simple script which does almost the same as ns.spawn()
. My script costs 2.6GB of RAM, while ns.spawn()
costs 2GB, so my script is only 0.6GB more expensive. Although you will need to use ns.run()
to run the spawning script of course, which costs 1GB. So in total this way is 1.6GB more expensive than just using ns.spawn()
.
On the plus side, the script calling quickSpawn.js
now has a lower RAM cost: down from 2GB for ns.spawn()
to 1GB for ns.run()
. And since quickSpawn.js
is just being run, not being imported, its RAM cost (2.6GB) does not count towards the RAM cost of the script calling it.
If immediately after calling the quickSpawn.js
script you terminate the running script (ns.exit()
), you can get away with a 0ms delay. If you need a bit more time, no problem. But you're no longer forced to wait the full 10 seconds that ns.spawn()
takes :)
Here's an example of the syntax to immediately respawn the current script with 4 threads and the same arguments:
ns.run(`quickSpawn.js`, 1, 0, ns.getScriptName(), 4, ...ns.args);
ns.exit();