mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 09:33:49 +01:00
Add ns.printf function
Behaviour is consistent with that of tprintf versus tprint and should be equivalent to ns.print(ns.sprintf(...))
This commit is contained in:
parent
07fe3c1906
commit
f2c4109211
@ -114,6 +114,7 @@ export const RamCosts: IMap<any> = {
|
||||
weaken: RamCostConstants.ScriptWeakenRamCost,
|
||||
weakenAnalyze: RamCostConstants.ScriptWeakenAnalyzeRamCost,
|
||||
print: 0,
|
||||
printf: 0,
|
||||
tprint: 0,
|
||||
clearLog: 0,
|
||||
disableLog: 0,
|
||||
|
@ -722,6 +722,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
workerScript.print(argsToString(args));
|
||||
},
|
||||
printf: function (format: string, ...args: any[]): void {
|
||||
if (typeof format !== "string") {
|
||||
throw makeRuntimeErrorMsg("printf", "First argument must be string for the format.");
|
||||
}
|
||||
workerScript.print(vsprintf(format, args));
|
||||
},
|
||||
tprint: function (...args: any[]): void {
|
||||
if (args.length === 0) {
|
||||
throw makeRuntimeErrorMsg("tprint", "Takes at least 1 argument.");
|
||||
|
11
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
11
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -4460,6 +4460,17 @@ export interface NS extends Singularity {
|
||||
*/
|
||||
print(...args: any[]): void;
|
||||
|
||||
/**
|
||||
* Prints a formatted string to the script’s logs.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* see: https://github.com/alexei/sprintf.js
|
||||
* @param format - format of the message
|
||||
* @param args - Value(s) to be printed.
|
||||
*/
|
||||
printf(format: string, ...args: any[]): void;
|
||||
|
||||
/**
|
||||
* Prints one or more values or variables to the Terminal.
|
||||
* @remarks
|
||||
|
Loading…
Reference in New Issue
Block a user