mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-08 08:43:53 +01:00
Add ns.getFunctionRamCost (#526)
This commit is contained in:
parent
294603fff8
commit
113af6e711
28
markdown/bitburner.ns.getfunctionramcost.md
Normal file
28
markdown/bitburner.ns.getfunctionramcost.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||||
|
|
||||||
|
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [getFunctionRamCost](./bitburner.ns.getfunctionramcost.md)
|
||||||
|
|
||||||
|
## NS.getFunctionRamCost() method
|
||||||
|
|
||||||
|
Get the ram cost of a netscript function.
|
||||||
|
|
||||||
|
**Signature:**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
getFunctionRamCost(name: string): number;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| name | string | The fully-qualified function name, without the leading <code>ns</code>. Example inputs: <code>hack</code>, <code>tprint</code>, <code>stock.getPosition</code>. |
|
||||||
|
|
||||||
|
**Returns:**
|
||||||
|
|
||||||
|
number
|
||||||
|
|
||||||
|
## Remarks
|
||||||
|
|
||||||
|
RAM cost: 0 GB
|
||||||
|
|
@ -74,6 +74,7 @@ export async function main(ns) {
|
|||||||
| [ftpcrack(host)](./bitburner.ns.ftpcrack.md) | Runs FTPCrack.exe on a server. |
|
| [ftpcrack(host)](./bitburner.ns.ftpcrack.md) | Runs FTPCrack.exe on a server. |
|
||||||
| [getBitNodeMultipliers(n, lvl)](./bitburner.ns.getbitnodemultipliers.md) | Get the current Bitnode multipliers. |
|
| [getBitNodeMultipliers(n, lvl)](./bitburner.ns.getbitnodemultipliers.md) | Get the current Bitnode multipliers. |
|
||||||
| [getFavorToDonate()](./bitburner.ns.getfavortodonate.md) | Returns the amount of Faction favor required to be able to donate to a faction. |
|
| [getFavorToDonate()](./bitburner.ns.getfavortodonate.md) | Returns the amount of Faction favor required to be able to donate to a faction. |
|
||||||
|
| [getFunctionRamCost(name)](./bitburner.ns.getfunctionramcost.md) | Get the ram cost of a netscript function. |
|
||||||
| [getGrowTime(host)](./bitburner.ns.getgrowtime.md) | Get the execution time of a grow() call. |
|
| [getGrowTime(host)](./bitburner.ns.getgrowtime.md) | Get the execution time of a grow() call. |
|
||||||
| [getHackingLevel()](./bitburner.ns.gethackinglevel.md) | Returns the player’s current hacking level. |
|
| [getHackingLevel()](./bitburner.ns.gethackinglevel.md) | Returns the player’s current hacking level. |
|
||||||
| [getHackingMultipliers()](./bitburner.ns.gethackingmultipliers.md) | Get hacking related multipliers. |
|
| [getHackingMultipliers()](./bitburner.ns.gethackingmultipliers.md) | Get hacking related multipliers. |
|
||||||
|
@ -534,6 +534,7 @@ export const RamCosts: RamCostTree<NSFull> = {
|
|||||||
getMoneySources: RamCostConstants.GetMoneySourcesCost,
|
getMoneySources: RamCostConstants.GetMoneySourcesCost,
|
||||||
mv: 0,
|
mv: 0,
|
||||||
getResetInfo: 1,
|
getResetInfo: 1,
|
||||||
|
getFunctionRamCost: 0,
|
||||||
tail: 0,
|
tail: 0,
|
||||||
toast: 0,
|
toast: 0,
|
||||||
moveTail: 0,
|
moveTail: 0,
|
||||||
@ -613,15 +614,13 @@ export const RamCosts: RamCostTree<NSFull> = {
|
|||||||
|
|
||||||
export function getRamCost(...args: string[]): number {
|
export function getRamCost(...args: string[]): number {
|
||||||
if (args.length === 0) {
|
if (args.length === 0) {
|
||||||
console.warn(`No arguments passed to getRamCost()`);
|
throw new Error(`No arguments passed to getRamCost()`);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let curr = RamCosts[args[0] as keyof typeof RamCosts];
|
let curr = RamCosts[args[0] as keyof typeof RamCosts];
|
||||||
for (let i = 1; i < args.length; ++i) {
|
for (let i = 1; i < args.length; ++i) {
|
||||||
if (curr == null) {
|
if (curr == null) {
|
||||||
console.warn(`Invalid function passed to getRamCost: ${args}`);
|
throw new Error(`Invalid function passed to getRamCost: ${args.join(".")}`);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const currType = typeof curr;
|
const currType = typeof curr;
|
||||||
@ -640,6 +639,5 @@ export function getRamCost(...args: string[]): number {
|
|||||||
return curr();
|
return curr();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.warn(`Unexpected type (${curr}) for value [${args}]`);
|
throw new Error(`Invalid function passed to getRamCost: ${args.join(".")}`);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,7 @@ import { ContentFilePath } from "./Paths/ContentFile";
|
|||||||
import { LiteratureName } from "./Literature/data/LiteratureNames";
|
import { LiteratureName } from "./Literature/data/LiteratureNames";
|
||||||
import { hasProgramExtension } from "./Paths/ProgramFilePath";
|
import { hasProgramExtension } from "./Paths/ProgramFilePath";
|
||||||
import { hasContractExtension } from "./Paths/ContractFilePath";
|
import { hasContractExtension } from "./Paths/ContractFilePath";
|
||||||
|
import { getRamCost } from "./Netscript/RamCostGenerator";
|
||||||
|
|
||||||
export const enums: NSEnums = {
|
export const enums: NSEnums = {
|
||||||
CityName,
|
CityName,
|
||||||
@ -1737,6 +1738,10 @@ export const ns: InternalAPI<NSFull> = {
|
|||||||
lastNodeReset: Player.lastNodeReset,
|
lastNodeReset: Player.lastNodeReset,
|
||||||
currentNode: Player.bitNodeN,
|
currentNode: Player.bitNodeN,
|
||||||
}),
|
}),
|
||||||
|
getFunctionRamCost: (ctx) => (_name) => {
|
||||||
|
const name = helpers.string(ctx, "name", _name);
|
||||||
|
return getRamCost(...name.split("."));
|
||||||
|
},
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
...NetscriptExtra(),
|
...NetscriptExtra(),
|
||||||
};
|
};
|
||||||
|
10
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
10
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -6510,6 +6510,16 @@ export interface NS {
|
|||||||
* */
|
* */
|
||||||
getResetInfo(): ResetInfo;
|
getResetInfo(): ResetInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ram cost of a netscript function.
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* RAM cost: 0 GB
|
||||||
|
*
|
||||||
|
* @param name - The fully-qualified function name, without the leading `ns`. Example inputs: `hack`, `tprint`, `stock.getPosition`.
|
||||||
|
*/
|
||||||
|
getFunctionRamCost(name: string): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse command line flags.
|
* Parse command line flags.
|
||||||
* @remarks
|
* @remarks
|
||||||
|
Loading…
Reference in New Issue
Block a user