From 708b800e36b45c9b0697a63b33c59a6b4f7191d8 Mon Sep 17 00:00:00 2001 From: Daniel Xie Date: Sun, 14 May 2017 20:43:10 -0500 Subject: [PATCH] Improved documentation for Netscript. Added a link to Netscript documentation in script editor --- css/menupages.css | 13 +++++++++++++ css/styles.css | 1 + index.html | 4 +++- src/Constants.js | 26 ++++++++++++++------------ src/Script.js | 8 ++++++++ src/engine.js | 1 + 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/css/menupages.css b/css/menupages.css index 9b2045289..0ec027941 100644 --- a/css/menupages.css +++ b/css/menupages.css @@ -41,6 +41,19 @@ display: inline-block; } +#script-editor-netscript-doc-button { + float: right; + display: inline-block; +} + +#script-editor-netscript-doc-warning { + background-color: #555; + color: #FFFFFF; +} +#script-editor-netscript-doc-warning:hover { + background-color: #666; +} + #script-editor-filename { float: left; resize: none; diff --git a/css/styles.css b/css/styles.css index f4c78224f..4a58be444 100644 --- a/css/styles.css +++ b/css/styles.css @@ -14,6 +14,7 @@ p { } h1 { + font-size: 22px; color: #66ff33; } diff --git a/index.html b/index.html index 2942dda96..b760337cb 100644 --- a/index.html +++ b/index.html @@ -139,7 +139,9 @@

Script name:

- Save & Close (Ctrl + b) + Save & Close (Ctrl + b) + Netscript Documentation +

Warning: You will lose unsaved content!

diff --git a/src/Constants.js b/src/Constants.js index 3dd231ea6..637ed2bc7 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -1,5 +1,5 @@ CONSTANTS = { - Version: "0.3", + Version: "0.4", //Max level for any skill, assuming no multipliers. Determined by max numerical value in javascript for experience //and the skill level formula in Player.js. Note that all this means it that when experience hits MAX_INT, then @@ -203,7 +203,7 @@ CONSTANTS = { "top - Displays all active scripts and their RAM usage

", 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.

" + - " Variables and data types
" + + "

Variables and data types


" + "The following data types are supported by Netscript:
" + "numeric - Integers and floats (6, 10.4999)
" + "string - Encapsulated by single or double quotes ('this is a string')
" + @@ -214,7 +214,7 @@ CONSTANTS = { "In the first example above, we are creating the variable i and assigning it a value of 5. In the second, " + "we are creating the variable s and assigning it the value of a string. Note that all expressions must be " + "ended with a semicolon.

" + - " Operators
" + + "

Operators


" + "The following operators are supported by Netscript:
" + " +
" + " -
" + @@ -229,7 +229,7 @@ CONSTANTS = { " >=
" + " ==
" + " !=

" + - " Functions
" + + "

Functions


" + "You can NOT define you own functions in Netscript (yet), but there are several built in functions that " + "you may use:

" + "hack(hostname/ip)
Core function that is used to hack servers to steal money and gain hacking experience. The argument passed in must be a string with " + @@ -237,28 +237,30 @@ CONSTANTS = { "sleep(n)
Suspends the script for n milliseconds.
Example: sleep(5000);

" + "grow(hostname/ip)
Use your hacking skills to increase the amount of money available on a server. The argument passed in " + "must be a string with either the IP or hostname of the target server.
Example: grow('foodnstuff');

" + - "print(x)
Prints a value or a variable to the scripts logs (which can be viewed with the 'tail [script]' terminal command

" + + "print(x)
Prints a value or a variable to the scripts logs (which can be viewed with the 'tail [script]' terminal command )

" + "nuke(hostname/ip)
Run NUKE.exe on the target server. NUKE.exe must exist on your home computer.
Example: nuke('foodnstuff');

" + "brutessh(hostname/ip)
Run BruteSSH.exe on the target server. BruteSSH.exe must exist on your home computer
Example: brutessh('foodnstuff');

" + "ftpcrack(hostname/ip)
Run FTPCrack.exe on the target server. FTPCrack.exe must exist on your home computer
Example: ftpcrack('foodnstuff');

" + "relaysmtp(hostname/ip)
Run relaySMTP.exe on the target server. relaySMTP.exe must exist on your home computer
Example: relaysmtp('foodnstuff');

" + "httpworm(hostname/ip)
Run HTTPWorm.exe on the target server. HTTPWorm.exe must exist on your home computer
Example: httpworm('foodnstuff');

" + "sqlinject(hostname/ip)
Run SQLInject.exe on the target server. SQLInject.exe must exist on your home computer
Example: sqlinject('foodnstuff');

" + - "While loop
" + + "

While loops


" + "A while loop is a control flow statement that repeatedly executes code as long as a condition is met.

" + - "while ([cond]) {
    [code]
}

" + + "while ([cond]) {
    [code]
}


" + "As long as [cond] remains true, the code block [code] will continuously execute. Example:

" + - "i = 0;
while (i < 10) {
    hack('foodnstuff');
    i = i + 1;
};

" + - "This code repeat the 'hack('foodnstuff')' command 10 times before it stops and exits. " + + "i = 0;
while (i < 10) {
    hack('foodnstuff');
    i = i + 1;
};


" + + "This code above repeats the 'hack('foodnstuff')' command 10 times before it stops and exits.

" + + "while(true) {
     hack('foodnstuff');
};


" + + "This while loop above is an infinite loop (continuously runs until the script is manually stopped) that repeatedly runs the 'hack('foodnstuff')' command. " + "Note that a semicolon is needed at closing bracket of the while loop, UNLESS it is at the end of the code

" + - "For loop
" + + "

For loops


" + "A for loop is another control flow statement that allows code to by repeated by iterations. The structure is:

" + - "for ([init]; [cond]; [post]) {
    code
}

" + + "for ([init]; [cond]; [post]) {
    code
};


" + "The [init] expression evaluates before the for loop begins. The for loop will continue to execute " + "as long as [cond] is met. The [post] expression will evaluate at the end of every iteration " + "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:

" + - "for (i = 0; i < 10; i = i+1) {
    hack('foodnstuff');
};


", + "for (i = 0; i < 10; i = i+1) {
    hack('foodnstuff');
};



", TutorialTravelingText:"There are six major cities in the world that you are able to travel to:

" + " Aevum
" + diff --git a/src/Script.js b/src/Script.js index d9429618a..ec0b28b35 100644 --- a/src/Script.js +++ b/src/Script.js @@ -10,6 +10,14 @@ function scriptEditorSaveCloseInit() { saveAndCloseScriptEditor(); return false; }); + + var netscriptDocButton = document.getElementById("script-editor-netscript-doc-button"); + netscriptDocButton.addEventListener("click", function() { + Engine.loadTutorialContent(); + Engine.displayTutorialContent(); + Engine.displayTutorialPage(CONSTANTS.TutorialNetscriptText); + return false; + }); }; document.addEventListener("DOMContentLoaded", scriptEditorSaveCloseInit, false); diff --git a/src/engine.js b/src/engine.js index bb938c3c7..f88d21cab 100644 --- a/src/engine.js +++ b/src/engine.js @@ -110,6 +110,7 @@ var Engine = { document.getElementById("script-editor-filename").value = filename; } document.getElementById("script-editor-text").value = code; + Engine.currentPage = Engine.Page.ScriptEditor; },