mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-30 04:47:03 +02:00
improve readability (in an editing context) of documentation
This commit is contained in:
@@ -2,14 +2,12 @@
|
||||
|
||||
## Infinite Loop in Scripts
|
||||
|
||||
If your game is frozen or stuck in any way, then the most likely culprit is an
|
||||
infinitely running loop in your script. To get past the freezing, run the game with
|
||||
`?noScripts` in the URL:
|
||||
If your game is frozen or stuck in any way, then the most likely culprit is an infinitely running loop in your script.
|
||||
To get past the freezing, run the game with `?noScripts` in the URL:
|
||||
|
||||
[Link to no freeze](https://danielyxie.github.io/bitburner/?noScripts)
|
||||
|
||||
Then, to fix your script, make sure you have a `sleep()` or any other timed function like `hack()` or
|
||||
`grow()` in any infinite loops:
|
||||
Then, to fix your script, make sure you have a `sleep()` or any other timed function like `hack()` or `grow()` in any infinite loops:
|
||||
|
||||
while(true) {
|
||||
// This is an infinite loop that does something
|
||||
@@ -17,8 +15,7 @@ Then, to fix your script, make sure you have a `sleep()` or any other timed func
|
||||
await ns.sleep(1000); // Add a 1s sleep to prevent freezing
|
||||
}
|
||||
|
||||
Also make sure that each while loop gets to the `await`ed function or `break`, for example the next snippet has a `sleep()`
|
||||
function, but it nor any possible conditional breaks are never reached and therefore will crash the game:
|
||||
Also make sure that each while loop gets to the `await`ed function or `break`, for example the next snippet has a `sleep()` function, but it nor any possible conditional breaks are never reached and therefore will crash the game:
|
||||
|
||||
while(true) {
|
||||
let currentMoney = ns.getServerMoneyAvailable("n00dles");
|
||||
@@ -34,8 +31,7 @@ function, but it nor any possible conditional breaks are never reached and there
|
||||
If `n00dles` current money is, for example, 75% of the maximum money, the script will reach neither `grow()` nor `break` and the game will crash.
|
||||
Adding a sleep like in the first example, or changing the code so that the `awaited` function or `break` is always reached, would prevent the crash.
|
||||
|
||||
Common infinite loop when translating the server purchasing script in starting guide to scripts is to have a
|
||||
while loop, where the condition's change is conditional:
|
||||
Common infinite loop when translating the server purchasing script in starting guide to scripts is to have a while loop, where the condition's change is conditional:
|
||||
|
||||
var ram = 8;
|
||||
var i = 0;
|
||||
@@ -50,19 +46,16 @@ while loop, where the condition's change is conditional:
|
||||
}
|
||||
|
||||
If the player does not currently have enough money to purchase a server, the `if`'s condition will be false and `++i` will not be reached.
|
||||
Since the script doesn't have `sleep()` and value `i` will not change without the `if` being true, this will crash the game. Adding a `sleep()`
|
||||
that is always reached would prevent the crash.
|
||||
Since the script doesn't have `sleep()` and value `i` will not change without the `if` being true, this will crash the game.
|
||||
Adding a `sleep()` that is always reached would prevent the crash.
|
||||
|
||||
## Blackscreen
|
||||
|
||||
If the game window becomes a black screen without the game itself crashing, this is caused by
|
||||
the game running too many concurrent scripts (the game runs on a browser and each tab can only
|
||||
use so much ram until it crashes). Depending on which scripts are running and your hardware,
|
||||
this number can vary between 50000 to 100000 instances (in version 2.0.2. In prior versions this number
|
||||
was about 1/5th of that). To prevent this from happening make sure to multithread
|
||||
the scripts as much as possible.
|
||||
If the game window becomes a black screen without the game itself crashing, this is caused by the game running too many concurrent scripts (the game runs on a browser and each tab can only use so much ram until it crashes).
|
||||
Depending on which scripts are running and your hardware, this number can vary between 50000 to 100000 instances (in version 2.0.2. In prior versions this number was about 1/5th of that).
|
||||
To prevent this from happening make sure to multithread the scripts as much as possible.
|
||||
|
||||
## Bug
|
||||
|
||||
Otherwise, the game is probably frozen/stuck due to a bug. To report a bug, follow
|
||||
the guidelines [here](https://github.com/bitburner-official/bitburner-src/blob/master/doc/CONTRIBUTING.md#reporting-bugs).
|
||||
Otherwise, the game is probably frozen/stuck due to a bug.
|
||||
To report a bug, follow the guidelines [here](https://github.com/bitburner-official/bitburner-src/blob/master/doc/CONTRIBUTING.md#reporting-bugs).
|
||||
|
||||
Reference in New Issue
Block a user