mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 15:43:49 +01:00
Merge pull request #2735 from Ninetailed/ns_printf
Add ns.printf function
This commit is contained in:
commit
77ba45df40
@ -114,6 +114,7 @@ export const RamCosts: IMap<any> = {
|
|||||||
weaken: RamCostConstants.ScriptWeakenRamCost,
|
weaken: RamCostConstants.ScriptWeakenRamCost,
|
||||||
weakenAnalyze: RamCostConstants.ScriptWeakenAnalyzeRamCost,
|
weakenAnalyze: RamCostConstants.ScriptWeakenAnalyzeRamCost,
|
||||||
print: 0,
|
print: 0,
|
||||||
|
printf: 0,
|
||||||
tprint: 0,
|
tprint: 0,
|
||||||
clearLog: 0,
|
clearLog: 0,
|
||||||
disableLog: 0,
|
disableLog: 0,
|
||||||
|
@ -722,6 +722,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
workerScript.print(argsToString(args));
|
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 {
|
tprint: function (...args: any[]): void {
|
||||||
if (args.length === 0) {
|
if (args.length === 0) {
|
||||||
throw makeRuntimeErrorMsg("tprint", "Takes at least 1 argument.");
|
throw makeRuntimeErrorMsg("tprint", "Takes at least 1 argument.");
|
||||||
|
11
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
11
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -4463,6 +4463,17 @@ export interface NS extends Singularity {
|
|||||||
*/
|
*/
|
||||||
print(...args: any[]): void;
|
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.
|
* Prints one or more values or variables to the Terminal.
|
||||||
* @remarks
|
* @remarks
|
||||||
|
Loading…
Reference in New Issue
Block a user