mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-23 17:53:00 +02:00
DOC: Move all docs into en/ subdirectory (#1505)
* DOC: Move all docs into en/ subdirectory PR #1502 is working on adding a Chinese translation to the docs. In general, I encouraged this (in #1452) as a path towards getting useful translated content in the game without requiring a massive refactor/rearchitecting of everything. To support this, this takes the first step of moving our docs into an en/ subdirectory, so that other languages can live alongside. No effort is made at this time to support or select between alternate languages; this is a pure-rename refactor.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
# "Netscript 2" Migration Guide
|
||||
|
||||
In previous versions, the game supported two script formats:
|
||||
|
||||
- `.script` (also sometimes called "Netscript 1" or "NS1") files are ran through an interpreter that is based on a version of Javascript from 2009 (ES5).
|
||||
|
||||
- `.js` (also sometimes called "Netscript 2" or "NS2") files are native javascript that is ran directly by the web browser. Modern features of javascript that are supported by your web browser are supported in `.js` files, because they are run as native js.
|
||||
|
||||
Support for running `.script` files was removed in version 3.0.
|
||||
|
||||
## Why do I have to change anything?
|
||||
|
||||
Since all ES5 code is still valid Javascript, you may be wondering why the old code doesn't just work when renamed to `.js`. In this section, some key differences are explained.
|
||||
|
||||
- **API access method**: In `.script` files, the game API is available at top-level scope within the file, as if they were at global scope. In `.js` files, the game API is passed as an argument into a script's `main` function, and is not available at top-level scope.
|
||||
- **Execution differences**: Running a `.script` file begins code execution at the top of the file. Running a `.js` file launches the `main` function (passing the game API in as the first argument, typically named `ns`).
|
||||
- **Timing differences**: In `.script` files, code execution contains automatic delays between every statement. In `.js` files, the code is being run natively so there are no builtin delays, so any needed delays must be added manually.
|
||||
|
||||
## Basic steps for script migration
|
||||
|
||||
1. Wrap the entire script inside of an exported main function, like so:
|
||||
|
||||
```js
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
// your code here
|
||||
}
|
||||
```
|
||||
|
||||
2. Add `ns.` as a prefix to all game functions or objects (such as `ns.hack()` or `ns.args`).
|
||||
3. If a function returns a `Promise`, you need to put the `await` keyword before it (With the JSDoc comment you can hover over the function to see the return type). Note that only functions declared as `async` are allowed to `await` anything, and typically you should also await the calls to your own `async` functions.
|
||||
4. Because there are no forced delays, an infinite loop will cause the game to hang if a delay is not manually added. Such loops should `await` a function (usually `ns.sleep()`) at least once to avoid this.
|
||||
5. The `var` keyword is rarely used in modern js for declaring variables. `let` or `const` (if the variable is never reassigned) keywords are preferred. This change is not required.
|
||||
|
||||
## Example migration
|
||||
|
||||
Original (`early-hacking-template.script`):
|
||||
|
||||
```js
|
||||
var target = "n00dles";
|
||||
var moneyThresh = getServerMaxMoney(target) * 0.9;
|
||||
var securityThresh = getServerMinSecurityLevel(target) + 5;
|
||||
|
||||
while (true) {
|
||||
if (getServerSecurityLevel(target) > securityThresh) {
|
||||
weaken(target);
|
||||
} else if (getServerMoneyAvailable(target) < moneyThresh) {
|
||||
grow(target);
|
||||
} else {
|
||||
hack(target);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Migrated (`early-hacking-template.js`):
|
||||
|
||||
```js
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
const target = "n00dles";
|
||||
const moneyThresh = ns.getServerMaxMoney(target) * 0.9;
|
||||
const securityThresh = ns.getServerMinSecurityLevel(target) + 5;
|
||||
|
||||
while (true) {
|
||||
if (ns.getServerSecurityLevel(target) > securityThresh) {
|
||||
await ns.weaken(target);
|
||||
} else if (ns.getServerMoneyAvailable(target) < moneyThresh) {
|
||||
await ns.grow(target);
|
||||
} else {
|
||||
await ns.hack(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Additional problems or edge cases
|
||||
|
||||
To get additional help with the migration, please join the [official Discord server](https://discord.gg/TFc3hKD).
|
||||
@@ -0,0 +1,36 @@
|
||||
# v1.0.0 Migration Guide
|
||||
|
||||
In v1.0.0 a few API have been broken.
|
||||
|
||||
migrated (only for ns2):
|
||||
|
||||
- bladeburner.getActionTime will return milliseconds instead of seconds.
|
||||
- getHackTime will return milliseconds instead of seconds.
|
||||
- getGrowTime will return milliseconds instead of seconds.
|
||||
- getWeakenTime will return milliseconds instead of seconds.
|
||||
- hackAnalyzePercent renamed to hackAnalyze
|
||||
- hackAnalyzePercent will return decimal instead of percentage
|
||||
- hackChance (not formulas.basic.hackChance) renamed to hackAnalyzeChance
|
||||
- formulas.basic is split into formulas.skills and formulas.hacking
|
||||
|
||||
not migrated (require manual changes sometimes):
|
||||
|
||||
- getPlayer().hacking_skill renamed `hacking`
|
||||
- same thing in sleeves
|
||||
- getPurchasedServers won't let you query for ips instead of hostnames.
|
||||
- getStats is deprecated in favor getPlayer
|
||||
- getCharacterInformation is deprecated in favor getPlayer
|
||||
- getServerRam deprecated in favor of getServerMaxRam and getServerUsedRam
|
||||
- getServerBaseSecurityLevel will be deprecated in favor of nothing, it's not really used.
|
||||
- sleep can no longer be called simultaneously, a new function called asleep will let you.
|
||||
- write returns promise (needs to be await ed).
|
||||
- scp returns a promise (needs to be await ed).
|
||||
- free port, write, read
|
||||
- write, read does not support port anymore, writePort and readPort does.
|
||||
|
||||
Upon loading v1.0.0 the game will apply some rules to change everything.
|
||||
The game never changes a file before making a backup called `BACKUP_filename.ext`, then,
|
||||
in the script it will change whatever it thinks it should change.
|
||||
But will prefix the modified line with the original line.
|
||||
|
||||
A file called `v1_DETECTED_CHANGES.txt` will point out every file with some possible problem.
|
||||
@@ -0,0 +1,97 @@
|
||||
# v2.0.0 Migration Guide
|
||||
|
||||
In v2.0.0 a few more APIs have been broken.
|
||||
|
||||
## Working
|
||||
|
||||
Working has been rebuilt from the ground up. The motivation for this change is that all
|
||||
different types of work all required different cached variables on the main Player object.
|
||||
This caused a lot of bugs and crashes. It's been reworked in such a way as to prevent bugs
|
||||
and make it nearly trivial to add new kinds of work.
|
||||
All work types give their reward immediately. No need to stop work to bank rewards like reputation.
|
||||
Faction and Company work no longer have a time limit.
|
||||
Company work no longer reduces rep gain by half for quitting early.
|
||||
Company factions now require 400k rep to join (up from 200k).
|
||||
Backdooring a company server reduces faction requirement to 300k.
|
||||
All types of work generally no longer keep track of cumulative gains like exp and reputation since it's applied instantly.
|
||||
|
||||
## commitCrime
|
||||
|
||||
Crime now loops, meaning after finishing one shoplift you start the next one with no input. While the signature
|
||||
has not changed, its behavior has. It also has a new 'focus' parameter.
|
||||
|
||||
## getPlayer
|
||||
|
||||
The following work-related fields are no longer included:
|
||||
|
||||
- workChaExpGained
|
||||
- currentWorkFactionName
|
||||
- workDexExpGained
|
||||
- workHackExpGained
|
||||
- createProgramReqLvl
|
||||
- workStrExpGained
|
||||
- companyName
|
||||
- crimeType
|
||||
- workRepGained
|
||||
- workChaExpGainRate
|
||||
- workType
|
||||
- workStrExpGainRate
|
||||
- isWorking
|
||||
- workRepGainRate
|
||||
- workDefExpGained
|
||||
- currentWorkFactionDescription
|
||||
- workHackExpGainRate
|
||||
- workAgiExpGainRate
|
||||
- workDexExpGainRate
|
||||
- workMoneyGained
|
||||
- workMoneyLossRate
|
||||
- workMoneyGainRate
|
||||
- createProgramName
|
||||
- workDefExpGainRate
|
||||
- workAgiExpGained
|
||||
- className
|
||||
|
||||
The reason for this, is that these fields are all, in one way or another, included in the new work field `currentWork`.
|
||||
Some of these values are also irrelevant.
|
||||
Take a look at the new singularity.getCurrentWork function:
|
||||
|
||||
All fields ending in `_mult` have been moved to the `mults` struct.
|
||||
For example: `getPlayer().hacking_skill_mult` => `getPlayer().mults.hacking_skill`
|
||||
|
||||
skills has been moved to the skills struct
|
||||
For example: `getPlayer().hacking` => `getPlayer().skills.hacking`
|
||||
|
||||
exp has been moved to the exp struct
|
||||
For example: `getPlayer().hacking_exp` => `getPlayer().exp.hacking`
|
||||
|
||||
hp has been moved to the hp struct
|
||||
For example: `getPlayer().max_hp` => `getPlayer().hp.max` or `hp.current`
|
||||
|
||||
`hasWseAccount`, `hasTixApiAccess`, `has4SData`, `has4SDataTixApi` have been removed and replaced with similar stock functions.
|
||||
|
||||
## workForCompany
|
||||
|
||||
The argument 'companyName' is now required.
|
||||
|
||||
## getScriptIncome & getScriptExpGain
|
||||
|
||||
These two functions used to have a call where, if no arguments were provided, it would return the total for all scripts. This caused weird signature.
|
||||
If you want to get the total income/exp for all scripts, use the new getTotalScriptIncome / getTotalScriptExpGain instead.
|
||||
|
||||
## scp
|
||||
|
||||
The last two arguments of scp have been reversed. The signature is now scp(files, destination, optional_source)
|
||||
|
||||
## Singularity
|
||||
|
||||
The top level singularity functions were deprecated a while ago in favor of the singularity namespace.
|
||||
This means calls like 'ns.connect' need to be changed to 'ns.singularity.connect'
|
||||
|
||||
## stock.buy, stock.sell, stock.short
|
||||
|
||||
These functions were renamed to stock.buyStock, stock.sellStock, and stock.buyShort because 'buy', 'sell', and 'short'
|
||||
are very common tokens that would trick the ram calculation.
|
||||
|
||||
## corporation.bribe
|
||||
|
||||
The ability to give shares as a bribe has been removed. The signature is now bribe(faction, money)
|
||||
Reference in New Issue
Block a user