mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-20 00:04:22 +02:00
Added tryWrite() as a native Netscript function. Updated documentation to reflect the fact that port handles no longer work in Netscript 1.0
This commit is contained in:
@@ -1847,6 +1847,25 @@ function NetscriptFunctions(workerScript) {
|
||||
throw makeRuntimeRejectMsg(workerScript, "Invalid argument passed in for write: " + port);
|
||||
}
|
||||
},
|
||||
tryWrite : function(port, data="") {
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("tryWrite", CONSTANTS.ScriptReadWriteRamCost);
|
||||
}
|
||||
updateDynamicRam("tryWrite", CONSTANTS.ScriptReadWriteRamCost);
|
||||
if (!isNaN(port)) {
|
||||
port = Math.round(port);
|
||||
if (port < 1 || port > CONSTANTS.NumNetscriptPorts) {
|
||||
throw makeRuntimeRejectMsg(workerScript, "ERROR: tryWrite() called on invalid port: " + port + ". Only ports 1-" + CONSTANTS.NumNetscriptPorts + " are valid.");
|
||||
}
|
||||
var port = NetscriptPorts[port-1];
|
||||
if (port == null || !(port instanceof NetscriptPort)) {
|
||||
throw makeRuntimeRejectMsg(workerScript, "Could not find port: " + port + ". This is a bug contact the game developer");
|
||||
}
|
||||
return port.tryWrite(data);
|
||||
} else {
|
||||
throw makeRuntimeRejectMsg(workerScript, "Invalid argument passed in for tryWrite: " + port);
|
||||
}
|
||||
},
|
||||
read : function(port) {
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("read", CONSTANTS.ScriptReadWriteRamCost);
|
||||
|
||||
Reference in New Issue
Block a user