mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +01:00
added basic type check to tryWritePort
This commit is contained in:
parent
6ed5a445a8
commit
e8954bc1ee
2
dist/bitburner.d.ts
vendored
2
dist/bitburner.d.ts
vendored
@ -3905,7 +3905,7 @@ export declare interface NS extends Singularity {
|
|||||||
* @param data - Data to write.
|
* @param data - Data to write.
|
||||||
* @returns True if the data is successfully written to the port, and false otherwise.
|
* @returns True if the data is successfully written to the port, and false otherwise.
|
||||||
*/
|
*/
|
||||||
tryWritePort(port: number, data: string[] | number): Promise<boolean>;
|
tryWritePort(port: number, data: string | number): Promise<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read content of a file.
|
* Read content of a file.
|
||||||
|
@ -1841,6 +1841,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
},
|
},
|
||||||
tryWritePort: function (port: any, data: any = ""): any {
|
tryWritePort: function (port: any, data: any = ""): any {
|
||||||
updateDynamicRam("tryWritePort", getRamCost(Player, "tryWritePort"));
|
updateDynamicRam("tryWritePort", getRamCost(Player, "tryWritePort"));
|
||||||
|
if ((typeof data !== "string" && typeof data !== "number") || isNS(data)) {
|
||||||
|
throw makeRuntimeErrorMsg(
|
||||||
|
"writePort",
|
||||||
|
`Trying to write invalid data to a port: only strings and numbers are valid.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
if (!isNaN(port)) {
|
if (!isNaN(port)) {
|
||||||
port = Math.round(port);
|
port = Math.round(port);
|
||||||
if (port < 1 || port > CONSTANTS.NumNetscriptPorts) {
|
if (port < 1 || port > CONSTANTS.NumNetscriptPorts) {
|
||||||
|
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -5555,7 +5555,7 @@ export interface NS extends Singularity {
|
|||||||
* @param data - Data to write.
|
* @param data - Data to write.
|
||||||
* @returns True if the data is successfully written to the port, and false otherwise.
|
* @returns True if the data is successfully written to the port, and false otherwise.
|
||||||
*/
|
*/
|
||||||
tryWritePort(port: number, data: string[] | number): Promise<boolean>;
|
tryWritePort(port: number, data: string | number): Promise<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read content of a file.
|
* Read content of a file.
|
||||||
|
Loading…
Reference in New Issue
Block a user