From e3c10e9f0f8c582517b6495410f9f005f81c2e3b Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Thu, 7 Nov 2024 09:44:38 +0700 Subject: [PATCH] MISC: Always add script's earnings to its parent (#1754) --- src/NetscriptWorker.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/NetscriptWorker.ts b/src/NetscriptWorker.ts index ba98c13ec..dbbb6e91e 100644 --- a/src/NetscriptWorker.ts +++ b/src/NetscriptWorker.ts @@ -330,21 +330,23 @@ Otherwise, this can also occur if you have attempted to launch a script from a t // Start the script's execution using the correct function for file type (isLegacyScript(workerScript.name) ? startNetscript1Script : startNetscript2Script)(workerScript) - // Once the code finishes (either resolved or rejected, doesnt matter), set its + // Once the code finishes (either resolved or rejected, doesn't matter), set its // running status to false .then(function () { - // On natural death, the earnings are transferred to the parent if it still exists. - if (parent && !parent.env.stopFlag) { - parent.scriptRef.onlineExpGained += runningScriptObj.onlineExpGained; - parent.scriptRef.onlineMoneyMade += runningScriptObj.onlineMoneyMade; - } killWorkerScript(workerScript); workerScript.log("", () => "Script finished running"); }) .catch(function (e) { handleUnknownError(e, workerScript); - workerScript.log("", () => (e instanceof ScriptDeath ? "Script killed." : "Script crashed due to an error.")); killWorkerScript(workerScript); + workerScript.log("", () => (e instanceof ScriptDeath ? "Script killed." : "Script crashed due to an error.")); + }) + .finally(() => { + // The earnings are transferred to the parent if it still exists. + if (parent && !parent.env.stopFlag) { + parent.scriptRef.onlineExpGained += runningScriptObj.onlineExpGained; + parent.scriptRef.onlineMoneyMade += runningScriptObj.onlineMoneyMade; + } }); return true; }