alainbryden / bitburner-scripts

My own scripts for playing bitburner
MIT License
603 stars 271 forks source link

helpers.js: cachedStockSymbols survives reset, suggests TIX access which may go away #304

Closed alainbryden closed 1 year ago

alainbryden commented 1 year ago

When the game resets to a new BN, unfortunately, the global variables belonging to scripts don't go away.

Global variables keeping their values from an old instance of the script is not a new problem - but it seems that until resently, variables whose values was at least good until the end of the bitnode weren't an issue. Now it seems to span across bitnodes.

This can lead to errors like the following: image

The solution here is that we can no longer use cachedStockSymbols for the getStocksValue helper, since it doesn't have a "main" function that gets called when its exported helpers are used. We might be able to workaround this by letting the user pass in an optional second argument which is a cached set of symbols. A ref string would be ideal, so that the cache could be managed by the caller instance's lifetime, but used by each call to the helper - unfortunately, I don't think such a thing exists in JS. Worst case, we just abandon the cache and this function gets a little more expensive.

I should have a skim to see if I can find any other globals that aren't getting reset, which might not have caused an issue up until now, but could cause issues if they survive a change of bitnodes.