diff --git a/src/NetscriptJSEvaluator.js b/src/NetscriptJSEvaluator.js index 65b714c06..d3241f557 100644 --- a/src/NetscriptJSEvaluator.js +++ b/src/NetscriptJSEvaluator.js @@ -74,7 +74,7 @@ function shouldCompile(script, scripts) { // compilation errors. if (!depScript) return true; - const depIsMoreRecent = depScript.updateTimestamp > script.updateTimestamp + const depIsMoreRecent = depScript.moduleSequenceNumber > script.moduleSequenceNumber return depIsMoreRecent; }); } diff --git a/src/Script/Script.ts b/src/Script/Script.ts index dc8a69367..3b9df8135 100644 --- a/src/Script/Script.ts +++ b/src/Script/Script.ts @@ -15,6 +15,8 @@ import { } from "../../utils/JSONReviver"; import { roundToTwo } from "../../utils/helpers/roundToTwo"; +let globalModuleSequenceNumber = 0; + export class Script { // Initializes a Script Object from a JSON save state static fromJSON(value: any): Script { @@ -32,7 +34,7 @@ export class Script { module: any = ""; // The timestamp when when the script was last updated. - updateTimestamp: number = 0; + moduleSequenceNumber: number; // Only used with NS2 scripts; the list of dependency script filenames. This is constructed // whenever the script is first evaluated, and therefore may be out of date if the script @@ -51,6 +53,7 @@ export class Script { this.ramUsage = 0; this.server = server; // IP of server this script is on this.module = ""; + this.moduleSequenceNumber = ++globalModuleSequenceNumber; if (this.code !== "") { this.updateRamUsage(otherScripts); } }; @@ -101,7 +104,7 @@ export class Script { // Marks that this script has been updated. Causes recompilation of NS2 modules. markUpdated() { this.module = ""; - this.updateTimestamp = Date.now(); + this.moduleSequenceNumber = ++globalModuleSequenceNumber; } /**