Description
Just capturing what's been discussed in Discord.
Player scripts invoked on startup (either because their running state is part of the save, or they are set as the startup script) can run before the game is fully initialized, and this can lead to an error if one of them triggers routing.
Normally, this error silently goes unnoticed (because the game's error handling isn't in place yet?), so the end-result is that the script that should have run on startup crashes and appears to have not run.
If the user script has any kind of error-handling though, they would catch an error like this:
Here's a sample script that can be used to reproduce the error fairly reliably just by running it, saving, then refreshing the game:
export async function main(ns) {
try {
ns.singularity.workForFaction("Tian Di Hui", "hacking");
while (true)
await ns.sleep(10000);
}
catch (err) {
ns.tprint("ERROR: An unexpected error occurred and now this script must terminate:\n" + (`${err.message}\n${err.stack}` ?? err))
}
}
You might have to update the faction to one you've joined.
As discussed, some possible solutions are:
- Don't start any user scripts until after the game is done initializing (speed runners might be mad)
- Just for the handful of singularity scripts which route, wrap the attempt to route in a try/catch. You can then either:
- ignore the attempt to route and move on (might have weird side-effects e.g. relating to focus penalties)
- Store the route destination in a variable, and once the UI is initialized, fulfill the route request ASAP. If multiple route-attempts occur, just save the most recent one? (I can only imagine this messing with scripts that try to interact with the UI, like auto-infiltration)
Activity