mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 15:43:49 +01:00
Minor fixes in and cleaning up typoes in license
This commit is contained in:
parent
2c68d17bc3
commit
99d774cf5a
BIN
doc/build/doctrees/environment.pickle
vendored
BIN
doc/build/doctrees/environment.pickle
vendored
Binary file not shown.
BIN
doc/build/doctrees/netscriptfunctions.doctree
vendored
BIN
doc/build/doctrees/netscriptfunctions.doctree
vendored
Binary file not shown.
@ -900,21 +900,47 @@ Functions should have some return value. Here is an example of defining and usin
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(sum([1, 2, 3, 4, 5]));
|
print(sum([1, 2, 3, 4, 5])); //Prints 15
|
||||||
print(sum([1, 10]));
|
print(sum([1, 10])); //Prints 11
|
||||||
|
|
||||||
The example above prints the following in its log::
|
For those with experience in other languages, especially Javascript, it may be important to note that
|
||||||
|
function declarations are not hoisted and must be declared BEFORE you use them.
|
||||||
|
For example, the following will cause an error saying `variable hello not defined`::
|
||||||
|
|
||||||
15
|
print(hello());
|
||||||
11
|
|
||||||
|
function hello() {
|
||||||
|
return "world";
|
||||||
|
}
|
||||||
|
|
||||||
|
The following will work fine::
|
||||||
|
|
||||||
|
function hello() {
|
||||||
|
return "world";
|
||||||
|
}
|
||||||
|
|
||||||
|
print(hello()); //Prints out "world"
|
||||||
|
|
||||||
**Note about variable scope in functions:**
|
**Note about variable scope in functions:**
|
||||||
|
|
||||||
Functions can access "global" variables declared outside of the function's scope. However, they cannot change the value of any "global" variables.
|
Functions can access "global" variables declared outside of the function's scope. However, they cannot change the value of any "global" variables.
|
||||||
Any changes to "global" variables will only be applied locally to the function. This also means that any variable that is first defined inside a
|
Any changes to "global" variables will only be applied locally to the function.
|
||||||
function will NOT be accessible outside of the function.
|
|
||||||
|
|
||||||
For example, the following code::
|
The following example shows that any change to a "global" variable
|
||||||
|
from inside a function only applies in the function's local scope::
|
||||||
|
|
||||||
|
function foo() {
|
||||||
|
i = 5;
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
print(i); //Prints 0
|
||||||
|
foo();
|
||||||
|
print(i); //Prints 0
|
||||||
|
|
||||||
|
Furthermore, this also means that any variable that is first defined inside a
|
||||||
|
function will NOT be accessible outside of the function as shown in the following example::
|
||||||
|
|
||||||
function sum(values) {
|
function sum(values) {
|
||||||
res = 0;
|
res = 0;
|
||||||
@ -933,22 +959,6 @@ results in the following runtime error::
|
|||||||
Args:[]
|
Args:[]
|
||||||
variable res not defined
|
variable res not defined
|
||||||
|
|
||||||
The following example shows that any change to "global" variable inside a function only applies in the function's local scope::
|
|
||||||
|
|
||||||
function foo() {
|
|
||||||
i = 5;
|
|
||||||
return "foo";
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
print(i);
|
|
||||||
foo();
|
|
||||||
print(i);
|
|
||||||
|
|
||||||
Results in the following log::
|
|
||||||
|
|
||||||
0
|
|
||||||
0
|
|
||||||
|
|
||||||
**Other Notes about creating your own functions:**
|
**Other Notes about creating your own functions:**
|
||||||
|
|
||||||
|
59
doc/build/html/netscriptfunctions.html
vendored
59
doc/build/html/netscriptfunctions.html
vendored
@ -1509,20 +1509,46 @@ false if the player clicks "No". The script's execution is halted unti
|
|||||||
<span class="k">return</span> <span class="n">res</span><span class="p">;</span>
|
<span class="k">return</span> <span class="n">res</span><span class="p">;</span>
|
||||||
<span class="p">}</span>
|
<span class="p">}</span>
|
||||||
|
|
||||||
<span class="nb">print</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]));</span>
|
<span class="nb">print</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]));</span> <span class="o">//</span><span class="n">Prints</span> <span class="mi">15</span>
|
||||||
<span class="nb">print</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">]));</span>
|
<span class="nb">print</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">]));</span> <span class="o">//</span><span class="n">Prints</span> <span class="mi">11</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
</div>
|
</div>
|
||||||
<p>The example above prints the following in its log:</p>
|
<p>For those with experience in other languages, especially Javascript, it may be important to note that
|
||||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="mi">15</span>
|
function declarations are not hoisted and must be declared BEFORE you use them.
|
||||||
<span class="mi">11</span>
|
For example, the following will cause an error saying <cite>variable hello not defined</cite>:</p>
|
||||||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="n">hello</span><span class="p">());</span>
|
||||||
|
|
||||||
|
<span class="n">function</span> <span class="n">hello</span><span class="p">()</span> <span class="p">{</span>
|
||||||
|
<span class="k">return</span> <span class="s2">"world"</span><span class="p">;</span>
|
||||||
|
<span class="p">}</span>
|
||||||
|
</pre></div>
|
||||||
|
</div>
|
||||||
|
<p>The following will work fine:</p>
|
||||||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">function</span> <span class="n">hello</span><span class="p">()</span> <span class="p">{</span>
|
||||||
|
<span class="k">return</span> <span class="s2">"world"</span><span class="p">;</span>
|
||||||
|
<span class="p">}</span>
|
||||||
|
|
||||||
|
<span class="nb">print</span><span class="p">(</span><span class="n">hello</span><span class="p">());</span> <span class="o">//</span><span class="n">Prints</span> <span class="n">out</span> <span class="s2">"world"</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
</div>
|
</div>
|
||||||
<p><strong>Note about variable scope in functions:</strong></p>
|
<p><strong>Note about variable scope in functions:</strong></p>
|
||||||
<p>Functions can access "global" variables declared outside of the function's scope. However, they cannot change the value of any "global" variables.
|
<p>Functions can access "global" variables declared outside of the function's scope. However, they cannot change the value of any "global" variables.
|
||||||
Any changes to "global" variables will only be applied locally to the function. This also means that any variable that is first defined inside a
|
Any changes to "global" variables will only be applied locally to the function.</p>
|
||||||
function will NOT be accessible outside of the function.</p>
|
<p>The following example shows that any change to a "global" variable
|
||||||
<p>For example, the following code:</p>
|
from inside a function only applies in the function's local scope:</p>
|
||||||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">function</span> <span class="n">foo</span><span class="p">()</span> <span class="p">{</span>
|
||||||
|
<span class="n">i</span> <span class="o">=</span> <span class="mi">5</span><span class="p">;</span>
|
||||||
|
<span class="k">return</span> <span class="s2">"foo"</span><span class="p">;</span>
|
||||||
|
<span class="p">}</span>
|
||||||
|
|
||||||
|
<span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
|
||||||
|
<span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">);</span> <span class="o">//</span><span class="n">Prints</span> <span class="mi">0</span>
|
||||||
|
<span class="n">foo</span><span class="p">();</span>
|
||||||
|
<span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">);</span> <span class="o">//</span><span class="n">Prints</span> <span class="mi">0</span>
|
||||||
|
</pre></div>
|
||||||
|
</div>
|
||||||
|
<p>Furthermore, this also means that any variable that is first defined inside a
|
||||||
|
function will NOT be accessible outside of the function as shown in the following example:</p>
|
||||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">function</span> <span class="nb">sum</span><span class="p">(</span><span class="n">values</span><span class="p">)</span> <span class="p">{</span>
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">function</span> <span class="nb">sum</span><span class="p">(</span><span class="n">values</span><span class="p">)</span> <span class="p">{</span>
|
||||||
<span class="n">res</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
|
<span class="n">res</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
|
||||||
<span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">values</span><span class="o">.</span><span class="n">length</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
|
<span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">values</span><span class="o">.</span><span class="n">length</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
|
||||||
@ -1541,23 +1567,6 @@ function will NOT be accessible outside of the function.</p>
|
|||||||
<span class="n">variable</span> <span class="n">res</span> <span class="ow">not</span> <span class="n">defined</span>
|
<span class="n">variable</span> <span class="n">res</span> <span class="ow">not</span> <span class="n">defined</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
</div>
|
</div>
|
||||||
<p>The following example shows that any change to "global" variable inside a function only applies in the function's local scope:</p>
|
|
||||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">function</span> <span class="n">foo</span><span class="p">()</span> <span class="p">{</span>
|
|
||||||
<span class="n">i</span> <span class="o">=</span> <span class="mi">5</span><span class="p">;</span>
|
|
||||||
<span class="k">return</span> <span class="s2">"foo"</span><span class="p">;</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
|
|
||||||
<span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
|
|
||||||
<span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
|
|
||||||
<span class="n">foo</span><span class="p">();</span>
|
|
||||||
<span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
|
|
||||||
</pre></div>
|
|
||||||
</div>
|
|
||||||
<p>Results in the following log:</p>
|
|
||||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="mi">0</span>
|
|
||||||
<span class="mi">0</span>
|
|
||||||
</pre></div>
|
|
||||||
</div>
|
|
||||||
<p><strong>Other Notes about creating your own functions:</strong></p>
|
<p><strong>Other Notes about creating your own functions:</strong></p>
|
||||||
<p>Defining a function does not create a Javascript function object in the underlying game code. This means that you cannot use any function
|
<p>Defining a function does not create a Javascript function object in the underlying game code. This means that you cannot use any function
|
||||||
you create in functions such as <a class="reference external" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort">Array.sort()</a> (not yet at least, I'll try to make it work in the future).</p>
|
you create in functions such as <a class="reference external" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort">Array.sort()</a> (not yet at least, I'll try to make it work in the future).</p>
|
||||||
|
2
doc/build/html/searchindex.js
vendored
2
doc/build/html/searchindex.js
vendored
File diff suppressed because one or more lines are too long
@ -900,15 +900,12 @@ Functions should have some return value. Here is an example of defining and usin
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(sum([1, 2, 3, 4, 5]));
|
print(sum([1, 2, 3, 4, 5])); //Prints 15
|
||||||
print(sum([1, 10]));
|
print(sum([1, 10])); //Prints 11
|
||||||
|
|
||||||
The example above prints the following in its log::
|
For those with experience in other languages, especially Javascript, it may be important to note that
|
||||||
|
function declarations are not hoisted and must be declared BEFORE you use them.
|
||||||
15
|
For example, the following will cause an error saying `variable hello not defined`::
|
||||||
11
|
|
||||||
|
|
||||||
For those with experience in other languages, especially Javascript it may be important to note that function declarations are not hoisted and must be declared BEFORE you use them.
|
|
||||||
|
|
||||||
print(hello());
|
print(hello());
|
||||||
|
|
||||||
@ -916,24 +913,21 @@ For those with experience in other languages, especially Javascript it may be im
|
|||||||
return "world";
|
return "world";
|
||||||
}
|
}
|
||||||
|
|
||||||
Will cause an error saying `variable hello not defined` whereas::
|
The following will work fine::
|
||||||
|
|
||||||
function hello() {
|
function hello() {
|
||||||
return "world";
|
return "world";
|
||||||
}
|
}
|
||||||
|
|
||||||
print(hello());
|
print(hello()); //Prints out "world"
|
||||||
|
|
||||||
Will print out
|
|
||||||
|
|
||||||
world
|
|
||||||
|
|
||||||
**Note about variable scope in functions:**
|
**Note about variable scope in functions:**
|
||||||
|
|
||||||
Functions can access "global" variables declared outside of the function's scope. However, they cannot change the value of any "global" variables.
|
Functions can access "global" variables declared outside of the function's scope. However, they cannot change the value of any "global" variables.
|
||||||
Any changes to "global" variables will only be applied locally to the function.
|
Any changes to "global" variables will only be applied locally to the function.
|
||||||
|
|
||||||
The following example shows that any change to "global" variable inside a function only applies in the function's local scope::
|
The following example shows that any change to a "global" variable
|
||||||
|
from inside a function only applies in the function's local scope::
|
||||||
|
|
||||||
function foo() {
|
function foo() {
|
||||||
i = 5;
|
i = 5;
|
||||||
@ -941,16 +935,12 @@ The following example shows that any change to "global" variable inside a functi
|
|||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
print(i);
|
print(i); //Prints 0
|
||||||
foo();
|
foo();
|
||||||
print(i);
|
print(i); //Prints 0
|
||||||
|
|
||||||
Results in the following log::
|
Furthermore, this also means that any variable that is first defined inside a
|
||||||
|
function will NOT be accessible outside of the function as shown in the following example::
|
||||||
0
|
|
||||||
0
|
|
||||||
|
|
||||||
Furthermore, this also means that any variable that is first defined inside a function will NOT be accessible outside of the function as shown in the following example::
|
|
||||||
|
|
||||||
function sum(values) {
|
function sum(values) {
|
||||||
res = 0;
|
res = 0;
|
||||||
@ -970,7 +960,6 @@ results in the following runtime error::
|
|||||||
variable res not defined
|
variable res not defined
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
**Other Notes about creating your own functions:**
|
**Other Notes about creating your own functions:**
|
||||||
|
|
||||||
Defining a function does not create a Javascript function object in the underlying game code. This means that you cannot use any function
|
Defining a function does not create a Javascript function object in the underlying game code. This means that you cannot use any function
|
||||||
|
@ -24,7 +24,7 @@ contains or is derived from the Software or any part thereof:
|
|||||||
|
|
||||||
(a) The distributed Software may not be used in any way for commercial gain and must not violate any of the restrictions
|
(a) The distributed Software may not be used in any way for commercial gain and must not violate any of the restrictions
|
||||||
set forth in Section 3.
|
set forth in Section 3.
|
||||||
(b) If you have modified the Software, you must cause cause the modified Software to carry prominent notices stating that
|
(b) If you have modified the Software, you must cause the modified Software to carry prominent notices stating that
|
||||||
you have modified the Software's files. Modifications must not alter or remove any copyright notices in the Software.
|
you have modified the Software's files. Modifications must not alter or remove any copyright notices in the Software.
|
||||||
(c) The distributed Software must include either a written copy of this License, or a prominent written indication that
|
(c) The distributed Software must include either a written copy of this License, or a prominent written indication that
|
||||||
the Software is covered by this License and written instructions for printing and/or displaying the copy of the License
|
the Software is covered by this License and written instructions for printing and/or displaying the copy of the License
|
||||||
|
Loading…
Reference in New Issue
Block a user