forked from alainbryden/bitburner-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsSet.js
More file actions
43 lines (35 loc) · 1001 Bytes
/
lsSet.js
File metadata and controls
43 lines (35 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { lsKeys } from './constants.js'
import { setLSItem, getLSItem } from './helpers.js'
export function autocomplete() {
return Object.keys(lsKeys);
}
/**
* @param {NS} ns
**/
export async function main(ns) {
if ( ns.args.length == 0 ) {
ns.tprint(`This script needs a recognized key!`);
ns.tprint('like: `run lsSet.js reserve 2e6` or `run lsSet.js working`');
return
}
let key = ns.args[0];
let safeKey = lsKeys[key.toUpperCase()];
if ( !safeKey ) {
ns.tprint(`That is not a recognized key. Use one of: `);
ns.tprint(Object.keys(lsKeys).join(", "));
return
}
if ( key.toUpperCase() === 'WORKING' ){
setLSItem(key, Date.now());
ns.tprint(`Set '${safeKey}': ${getLSItem(key)}`);
return
}
if ( ns.args.length < 2 ) {
ns.tprint(`This script needs a value!`);
ns.tprint('like: `run lsSet.js reserve 2e6`');
return
}
let value = ns.args[1];
setLSItem(key, value);
ns.tprint(`Set '${safeKey}': ${getLSItem(key)}`);
}