mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 01:33:54 +01:00
UI Improvement to script editor. FIxed some bugs in new Netscript commands
This commit is contained in:
parent
3919d3e97a
commit
5039a03732
@ -23,11 +23,11 @@
|
||||
#script-editor-container {
|
||||
position: fixed;
|
||||
padding-top: 10px;
|
||||
padding-left: 10px;
|
||||
height: 100%;
|
||||
margin-left: 10%;
|
||||
width: 75%;
|
||||
width: 99%;
|
||||
color: #66ff33;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
#script-editor-filename-tag {
|
||||
@ -36,14 +36,12 @@
|
||||
float: left;
|
||||
}
|
||||
|
||||
#script-editor-save-and-close-button {
|
||||
float: right;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#script-editor-save-and-close-button,
|
||||
#script-editor-netscript-doc-button {
|
||||
float: right;
|
||||
display: inline-block;
|
||||
width: 50%;
|
||||
margin-right: 25%;
|
||||
}
|
||||
|
||||
#script-editor-netscript-doc-warning {
|
||||
@ -58,9 +56,9 @@
|
||||
float: left;
|
||||
resize: none;
|
||||
color: #66ff33;
|
||||
width: 100%;
|
||||
margin: 4px;
|
||||
padding: 4px;
|
||||
width: 75%;
|
||||
margin: 10px;
|
||||
padding: 5px;
|
||||
|
||||
border: 2px solid white;
|
||||
-webkit-box-shadow:
|
||||
@ -81,10 +79,10 @@
|
||||
|
||||
#script-editor-text {
|
||||
color: #66ff33;
|
||||
width: 100%;
|
||||
width: 75%;
|
||||
height: 100%;
|
||||
margin: 4px;
|
||||
padding: 4px;
|
||||
margin: 10px;
|
||||
padding: 5px;
|
||||
|
||||
border: 2px solid white;
|
||||
-webkit-box-shadow:
|
||||
|
@ -152,6 +152,7 @@
|
||||
<br>
|
||||
<br><br>
|
||||
<textarea id="script-editor-text" tabindex="2" autofocus> </textarea>
|
||||
<p> <br><br> </p>
|
||||
</div>
|
||||
|
||||
<!-- Active scripts info page -->
|
||||
|
@ -198,13 +198,18 @@ CONSTANTS = {
|
||||
"section of this 'Tutorial' page. <br><br>Running a script requires RAM. The more complex a script is, the more RAM " +
|
||||
"it requires to run. Scripts can be run on any server you have root access to. <br><br>" +
|
||||
"Here are some Terminal commands that are useful when working with scripts: <br>" +
|
||||
"free - Shows the current server's RAM usage <br>" +
|
||||
"free - Shows the current server's RAM usage and availability <br>" +
|
||||
"kill [script] - Stops a script that is running <br>" +
|
||||
"mem [script] - Check how much RAM a script requires to run<br>" +
|
||||
"nano [script] - Create/Edit a script <br>" +
|
||||
"ps - Displays all scripts that are actively running on the current server<br>" +
|
||||
"run [script] - Run a script <br>" +
|
||||
"tail [script] - Displays a script's logs<br>" +
|
||||
"top - Displays all active scripts and their RAM usage <br><br>",
|
||||
"top - Displays all active scripts and their RAM usage <br><br>" +
|
||||
"<strong>Note that because of the way the Netscript interpreter is implemented, " +
|
||||
"whenever you reload or re-open the game all of the scripts that you are running will " +
|
||||
"start running from the BEGINNING of the code. The game does not keep track of where exactly " +
|
||||
"the execution of a script is when it saves/loads. </strong><br><br>",
|
||||
TutorialNetscriptText: "Netscript is a very simple programming language implemented for this game. The language has " +
|
||||
"your basic programming constructs and several built-in commands that are used to hack. <br><br>" +
|
||||
"<u><h1> Variables and data types </h1></u><br>" +
|
||||
@ -250,6 +255,13 @@ CONSTANTS = {
|
||||
"<i>relaysmtp(hostname/ip)</i><br>Run relaySMTP.exe on the target server. relaySMTP.exe must exist on your home computer <br> Example: relaysmtp('foodnstuff');<br><br>" +
|
||||
"<i>httpworm(hostname/ip)</i><br>Run HTTPWorm.exe on the target server. HTTPWorm.exe must exist on your home computer <br> Example: httpworm('foodnstuff');<br><br>" +
|
||||
"<i>sqlinject(hostname/ip)</i><br>Run SQLInject.exe on the target server. SQLInject.exe must exist on your home computer <br> Example: sqlinject('foodnstuff');<br><br>" +
|
||||
"<i>run(script)</i> <br> Run a script as a separate process. The argument that is passed in is the name of the script as a string. This function can only " +
|
||||
"be used to run scripts located on the same server. Returns true if the script is successfully started, and false otherwise. Requires a significant amount " +
|
||||
"of RAM to run this command.<br>Example: run('hack-foodnstuff.script'); <br> The example above will try and launch the 'hack-foodnstuff.script' script on " +
|
||||
"the current server, if it exists. <br><br>" +
|
||||
"<i>getHackingLevel() </i><br> Returns the Player's current hacking level <br><br> " +
|
||||
"<i>getServerMoneyAvailable(hostname/ip)</i><br> Returns the amount of money available on a server. The argument passed in must be a string with either the " +
|
||||
"hostname or IP of the target server. <br> Example: getServerMoneyAvailable('foodnstuff');<br><br>" +
|
||||
"<u><h1>While loops </h1></u><br>" +
|
||||
"A while loop is a control flow statement that repeatedly executes code as long as a condition is met. <br><br> " +
|
||||
"<i>while (<i>[cond]</i>) {<br> <i>[code]</i><br>}</i><br><br>" +
|
||||
@ -267,7 +279,21 @@ CONSTANTS = {
|
||||
"of the for loop. The following example shows code that will do the same thing as the while loop example above, " +
|
||||
"except using a for loop instead: <br><br>" +
|
||||
"<i>for (i = 0; i < 10; i = i+1) { <br> hack('foodnstuff');<br>}; </i><br><br>" +
|
||||
"<u><h1> If statements </h1></u>",
|
||||
"<u><h1> If statements </h1></u><br>" +
|
||||
"If/Elif/Else statements are conditional statements used to perform different actions based on different conditions: <br><br>" +
|
||||
"<i>if (condition1) {<br> code1<br>} elif (condition2) {<br> code2<br>} else {<br>" +
|
||||
" code3<br>}</i><br><br>" +
|
||||
"In the code above, first <i>condition1</i> will be checked. If this condition is true, then <i>code1</i> will execute and the " +
|
||||
"rest of the if/elif/else statement will be skipped. If <i>condition1</i> is NOT true, then the code will then go on to check " +
|
||||
"<i>condition2</i>. If <i>condition2</i> is true, then <i>code2</i> will be executed, and the rest of the if/elif/else statement " +
|
||||
"will be skipped. If none of the conditions are true, then the code within the else block (<i>code3</i>) will be executed. " +
|
||||
"Note that a conditional statement can have any number of elif statements. <br><br>" +
|
||||
"Example: <br><br>" +
|
||||
"if(getServerMoneyAvailable('foodnstuff') > 200000) {<br> hack('foodnstuff');<br>" +
|
||||
"} else {<br> grow('foodnstuff');<br>};<br><br>" +
|
||||
"The code above will use the getServerMoneyAvailable() function to check how much money there is on the 'foodnstuff' server. " +
|
||||
"If there is more than $200,000, then it will try to hack that server. If there is $200,000 or less on the server, " +
|
||||
"then the code will call grow('foodnstuff') instead and add more money to the server.<br><br>",
|
||||
|
||||
TutorialTravelingText:"There are six major cities in the world that you are able to travel to: <br><br> " +
|
||||
" Aevum<br>" +
|
||||
|
@ -16,12 +16,13 @@ HacknetNode.prototype.updateMoneyGainRate = function() {
|
||||
//How much extra $/s is gained per level
|
||||
var gainPerLevel = CONSTANTS.HacknetNodeMoneyGainPerLevel;
|
||||
|
||||
//Each CPU core doubles the speed. Every 1GB of ram adds 20% increase
|
||||
//Each CPU core doubles the speed. Every 1GB of ram adds 15% increase
|
||||
this.moneyGainRatePerSecond = (this.level * gainPerLevel) *
|
||||
Math.pow(1.2, this.ram-1) *
|
||||
Math.pow(1.15, this.ram-1) *
|
||||
this.numCores * Player.hacknet_node_money_mult;
|
||||
if (isNaN(this.moneyGainRatePerSecond)) {
|
||||
throw new Error("Money gain rate calculated for Hacknet Node is NaN");
|
||||
this.moneyGainRatePerSecond = 0;
|
||||
dialogBoxCreate("Error in calculating Hacknet Node production. Please report to game developer");
|
||||
}
|
||||
|
||||
updateTotalHacknetProduction();
|
||||
|
@ -351,8 +351,8 @@ function evaluate(exp, workerScript) {
|
||||
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|grow() call has incorrect number of arguments. Takes 1 argument");
|
||||
}
|
||||
var ipPromise = evaluate(exp.args[0], workerScript);
|
||||
|
||||
ipPromise.then(function(ip) {
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
var server = getServer(ip);
|
||||
if (server == null) {
|
||||
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Invalid IP or hostname passed into grow() command");
|
||||
@ -393,6 +393,7 @@ function evaluate(exp, workerScript) {
|
||||
}
|
||||
var ipPromise = evaluate(exp.args[0], workerScript);
|
||||
ipPromise.then(function(ip) {
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
var server = getServer(ip);
|
||||
if (server == null) {
|
||||
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Invalid IP or hostname passed into nuke() command");
|
||||
@ -438,6 +439,7 @@ function evaluate(exp, workerScript) {
|
||||
}
|
||||
var ipPromise = evaluate(exp.args[0], workerScript);
|
||||
ipPromise.then(function(ip) {
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
var server = getServer(ip);
|
||||
if (server == null) {
|
||||
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Invalid IP or hostname passed into brutessh() command");
|
||||
@ -479,6 +481,7 @@ function evaluate(exp, workerScript) {
|
||||
}
|
||||
var ipPromise = evaluate(exp.args[0], workerScript);
|
||||
ipPromise.then(function(ip) {
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
var server = getServer(ip);
|
||||
if (server == null) {
|
||||
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Invalid IP or hostname passed into ftpcrack() command");
|
||||
@ -520,6 +523,7 @@ function evaluate(exp, workerScript) {
|
||||
}
|
||||
var ipPromise = evaluate(exp.args[0], workerScript);
|
||||
ipPromise.then(function(ip) {
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
var server = getServer(ip);
|
||||
if (server == null) {
|
||||
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Invalid IP or hostname passed into relaysmtp() command");
|
||||
@ -561,6 +565,7 @@ function evaluate(exp, workerScript) {
|
||||
}
|
||||
var ipPromise = evaluate(exp.args[0], workerScript);
|
||||
ipPromise.then(function(ip) {
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
var server = getServer(ip);
|
||||
if (server == null) {
|
||||
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Invalid IP or hostname passed into relaysmtp() command");
|
||||
@ -602,6 +607,7 @@ function evaluate(exp, workerScript) {
|
||||
}
|
||||
var ipPromise = evaluate(exp.args[0], workerScript);
|
||||
ipPromise.then(function(ip) {
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
var server = getServer(ip);
|
||||
if (server == null) {
|
||||
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Invalid IP or hostname passed into sqlinject() command");
|
||||
@ -638,7 +644,6 @@ function evaluate(exp, workerScript) {
|
||||
reject(e);
|
||||
});
|
||||
} else if (exp.func.value == "run") {
|
||||
console.log("run() called");
|
||||
if (exp.args.length != 1) {
|
||||
reject("|"+workerScript.serverIp+"|"+workerScript.name+"|run() call has incorrect number of arguments. Takes 1 argument");
|
||||
}
|
||||
@ -661,12 +666,12 @@ function evaluate(exp, workerScript) {
|
||||
reject(e);
|
||||
});
|
||||
} else if (exp.func.value == "getHackingLevel") {
|
||||
console.log("getHackingLevel called");
|
||||
if (exp.args.length != 0) {
|
||||
reject("|"+workerScript.serverIp+"|"+workerScript.name+"|getHackingLevel() call has incorrect number of arguments. Takes 0 arguments");
|
||||
}
|
||||
setTimeout(function() {
|
||||
console.log("About to resolve getHackingLevel");
|
||||
Player.updateSkillLevels();
|
||||
workerScript.scriptRef.log("getHackingLevel() returned " + Player.hacking_skill);
|
||||
resolve(Player.hacking_skill);
|
||||
}, CONSTANTS.CodeInstructionRunTime);
|
||||
} else if (exp.func.value == "getServerMoneyAvailable") {
|
||||
@ -682,6 +687,7 @@ function evaluate(exp, workerScript) {
|
||||
workerScript.scriptRef.log("Cannot getServerMoneyAvailable(). Invalid IP or hostname passed in: " + ip);
|
||||
return;
|
||||
}
|
||||
workerScript.scriptRef.log("getServerMoneyAvailable() returned " + server.moneyAvailable);
|
||||
resolve(server.moneyAvailable);
|
||||
}, CONSTANTS.CodeInstructionRunTime);
|
||||
}, function(e) {
|
||||
@ -926,12 +932,15 @@ function apply_op(op, a, b) {
|
||||
//Run a script from inside a script using run() command
|
||||
function runScriptFromScript(server, scriptname, workerScript) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var env = workerScript.env;
|
||||
if (env.stopFlag) {reject(workerScript);}
|
||||
setTimeout(function() {
|
||||
//Check if the script is already running
|
||||
for (var i = 0; i < server.runningScripts.length; ++i) {
|
||||
if (server.runningScripts[i] == scriptname) {
|
||||
workerScript.scriptRef.log(scriptname + " is already running on " + server.hostname);
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -957,6 +966,7 @@ function runScriptFromScript(server, scriptname, workerScript) {
|
||||
server.runningScripts.push(script.filename); //Push onto runningScripts
|
||||
addWorkerScript(script, server);
|
||||
resolve(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ function runScriptsLoop() {
|
||||
if (workerScripts[i].running == false && workerScripts[i].env.stopFlag == false) {
|
||||
try {
|
||||
var ast = Parser(Tokenizer(InputStream(workerScripts[i].code)));
|
||||
console.log(ast);
|
||||
//console.log(ast);
|
||||
} catch (e) {
|
||||
dialogBoxCreate("Syntax ERROR in " + workerScripts[i].name + ":", e, "", "");
|
||||
workerScripts[i].env.stopFlag = true;
|
||||
|
Loading…
Reference in New Issue
Block a user