bitburner-src/src/Script/RunningScriptHelpers.ts
2021-10-07 16:56:01 -04:00

23 lines
636 B
TypeScript

import { GetServer } from "../Server/AllServers";
import { RunningScript } from "./RunningScript";
export function getRamUsageFromRunningScript(script: RunningScript): number {
if (script.ramUsage != null && script.ramUsage > 0) {
return script.ramUsage; // Use cached value
}
const server = GetServer(script.server);
if (server == null) {
return 0;
}
for (let i = 0; i < server.scripts.length; ++i) {
if (server.scripts[i].filename === script.filename) {
// Cache the ram usage for the next call
script.ramUsage = server.scripts[i].ramUsage;
return script.ramUsage;
}
}
return 0;
}