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:
danielyxie
2018-08-30 15:27:47 -05:00
parent 30f8c4a6f0
commit 395fc3b9df
7 changed files with 72 additions and 17 deletions
+6 -4
View File
@@ -493,10 +493,12 @@ let CONSTANTS = {
"World Stock Exchange account and TIX API Access<br>",
LatestUpdate:
"v0.40.3<br>" +
"* b1t_flum3.exe program can now be created immediately at Hacking level 1 (rather than hacking level 5)<br>" +
"* UI improvements for the character overview panel and the left-hand menu (by mat-jaworski)<br>" +
"* Improved the introductory tutorial<br>"
`v0.40.3<br>
* b1t_flum3.exe program can now be created immediately at Hacking level 1 (rather than hacking level 5)
* UI improvements for the character overview panel and the left-hand menu (by mat-jaworski)
* Updated documentation to reflect the fact that Netscript port handles (getPortHandle()) only works in NetscriptJS (2.0), NOT Netscript 1.0
* Added tryWrite() Netscript function
* Improved the introductory tutorial`
}
+1 -1
View File
@@ -268,7 +268,7 @@ function iTutorialEvaluateStep() {
"written in the Netscript language, a programming language created for " +
"this game. <strong style='background-color:#444;'>There are details about the Netscript language in the documentation, which " +
"can be accessed in the 'Tutorial' tab on the main navigation menu. I highly suggest you check " +
"it out after this tutorial. </strong> For now, just copy " +
"it out after this tutorial.</strong> For now, just copy " +
"and paste the following code into the script editor: <br><br>" +
"while(true) { <br>" +
"&nbsp;&nbsp;hack('foodnstuff'); <br>" +
+19
View File
@@ -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);