mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-21 15:12:06 +02:00
NETSCRIPT: allow getFunctionRamCost to get base RAM cost for scripts (#2771)
This commit is contained in:
@@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
## NS.getFunctionRamCost() method
|
## NS.getFunctionRamCost() method
|
||||||
|
|
||||||
Get the ram cost of a netscript function.
|
Get the RAM cost of a netscript function.
|
||||||
|
|
||||||
|
The base RAM cost per script thread can also be retrieved by using `"baseCost"` as argument to this function.
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ string
|
|||||||
|
|
||||||
</td><td>
|
</td><td>
|
||||||
|
|
||||||
The fully-qualified function name, without the leading `ns`<!-- -->. Example inputs: `hack`<!-- -->, `tprint`<!-- -->, `stock.getPosition`<!-- -->.
|
The fully-qualified function name, without the leading `ns`<!-- -->.
|
||||||
|
|
||||||
|
|
||||||
</td></tr>
|
</td></tr>
|
||||||
@@ -56,3 +58,13 @@ number
|
|||||||
|
|
||||||
RAM cost: 0 GB
|
RAM cost: 0 GB
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
|
||||||
|
```js
|
||||||
|
const RAM_baseCost = ns.getFunctionRamCost('baseCost');
|
||||||
|
const RAM_for_hack = ns.getFunctionRamCost('hack');
|
||||||
|
const RAM_for_tprint = ns.getFunctionRamCost('tprint');
|
||||||
|
const RAM_for_stock_getPosition = ns.getFunctionRamCost('stock.getPosition');
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -718,7 +718,9 @@ Get the metadata of a file.
|
|||||||
|
|
||||||
</td><td>
|
</td><td>
|
||||||
|
|
||||||
Get the ram cost of a netscript function.
|
Get the RAM cost of a netscript function.
|
||||||
|
|
||||||
|
The base RAM cost per script thread can also be retrieved by using `"baseCost"` as argument to this function.
|
||||||
|
|
||||||
|
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ import { hasScriptExtension } from "./Paths/ScriptFilePath";
|
|||||||
import { hasTextExtension } from "./Paths/TextFilePath";
|
import { hasTextExtension } from "./Paths/TextFilePath";
|
||||||
import { ContentFilePath } from "./Paths/ContentFile";
|
import { ContentFilePath } from "./Paths/ContentFile";
|
||||||
import { hasContractExtension } from "./Paths/ContractFilePath";
|
import { hasContractExtension } from "./Paths/ContractFilePath";
|
||||||
import { getRamCost } from "./Netscript/RamCostGenerator";
|
import { getRamCost, RamCostConstants } from "./Netscript/RamCostGenerator";
|
||||||
import { getEnumHelper } from "./utils/EnumHelper";
|
import { getEnumHelper } from "./utils/EnumHelper";
|
||||||
import { ServerConstants } from "./Server/data/Constants";
|
import { ServerConstants } from "./Server/data/Constants";
|
||||||
import { assertFunctionWithNSContext } from "./Netscript/TypeAssertion";
|
import { assertFunctionWithNSContext } from "./Netscript/TypeAssertion";
|
||||||
@@ -1500,6 +1500,9 @@ export const ns: InternalAPI<NSFull> = {
|
|||||||
}),
|
}),
|
||||||
getFunctionRamCost: (ctx) => (_name) => {
|
getFunctionRamCost: (ctx) => (_name) => {
|
||||||
const name = helpers.string(ctx, "name", _name);
|
const name = helpers.string(ctx, "name", _name);
|
||||||
|
if (name === "baseCost") {
|
||||||
|
return RamCostConstants.Base;
|
||||||
|
}
|
||||||
return getRamCost(name.split("."), true);
|
return getRamCost(name.split("."), true);
|
||||||
},
|
},
|
||||||
tprintRaw: () => (value) => {
|
tprintRaw: () => (value) => {
|
||||||
|
|||||||
+12
-2
@@ -9002,12 +9002,22 @@ export interface NS {
|
|||||||
getResetInfo(): ResetInfo;
|
getResetInfo(): ResetInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ram cost of a netscript function.
|
* Get the RAM cost of a netscript function.
|
||||||
|
*
|
||||||
|
* The base RAM cost per script thread can also be retrieved by using `"baseCost"` as argument to this function.
|
||||||
*
|
*
|
||||||
* @remarks
|
* @remarks
|
||||||
* RAM cost: 0 GB
|
* RAM cost: 0 GB
|
||||||
*
|
*
|
||||||
* @param name - The fully-qualified function name, without the leading `ns`. Example inputs: `hack`, `tprint`, `stock.getPosition`.
|
* @param name - The fully-qualified function name, without the leading `ns`.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```js
|
||||||
|
* const RAM_baseCost = ns.getFunctionRamCost('baseCost');
|
||||||
|
* const RAM_for_hack = ns.getFunctionRamCost('hack');
|
||||||
|
* const RAM_for_tprint = ns.getFunctionRamCost('tprint');
|
||||||
|
* const RAM_for_stock_getPosition = ns.getFunctionRamCost('stock.getPosition');
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
getFunctionRamCost(name: string): number;
|
getFunctionRamCost(name: string): number;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user