Getting started¶
The folder¶
/fkdr script folder opens your scripts folder and prints where it is.
scripts/ *.js one file, one module. _name.js is ignored.
scripts/lib/ *.js never loaded by itself; for require()
scripts/data/ *.json per-script storage
Compiled extensions (.jar, not sandboxed) go in the extensions folder next to it. The layout is flat on purpose: there are no per-script folders and no manifest.
Your first script¶
fkdr installs no scripts. The folder holds only what you put there or install from the portal (Scripts → Discover). /fkdr script new mything writes a starter file and loads it; edit it, then /fkdr script reload mything.
A script runs when that script is switched on: its row in Scripts → Installed, or /fkdr script on <name>. There is no switch for the whole script system.
Old example scripts
Versions before 0.33.5 wrote example files (example.js, lobby-threat.js, enemy-highlight.js, uuid-lookup.js, cute-visuals.js). The first launch of 0.33.5 removes them once, but only copies nobody edited. An edited copy is yours and stays, and so does anything installed from the portal.
Switching a script off¶
A file whose name begins with _ is ignored. That is how you switch a script off without deleting it, and it works from a file manager with the game closed, which is what you want when a script is the reason the game will not start.
The shape of a script¶
A script is a plain JavaScript file. Its top-level code runs once at load; the interesting parts are the functions it defines.
script.meta({
name: 'Bed Alert',
author: 'you',
version: '1.0.0',
description: 'Shouts when an enemy bed is close to breaking.'
});
function onLoad() {
settings.bool('Alert', true, 'Shout when a bed is close.');
}
function onChat(e) {
if (e.message.indexOf('gg') === 0) chat.print('gg');
}
Everything in meta is optional. Without it, the script is named after its file. The name is also available as the bare global scriptName and as script.name.
Every script appears in the menu under Scripts as a module with its own on/off switch, keybind and settings. That is fixed: a script cannot file itself under Render or Bed Wars, because the sidebar is the one place you can answer "what is this and where did it come from".
Script names¶
A script becomes a module named after its file, and module names are unique across the whole mod. So hud.js, stats.js, anything else already taken by a built-in module, and scripts.js are refused: the script is listed as broken by /fkdr script, the reason names the clash, and nothing is registered. Rename the file and reload. /fkdr list shows every name in use.
What happens when a script goes away¶
Delete a script, or rename it to _name.js, and after the next reload its module leaves the menu entirely rather than sitting there as a dead switch. Its settings are kept, so renaming it back gives you the script with every setting exactly as you left it.
The one case that does lose settings is deleting a file and reloading and quitting, all in the same session. After that there is nothing on disk to associate the settings with.
Language¶
Modern JavaScript (ES6): let, const, arrow functions, template literals, for…of, destructuring, Map/Set, JSON, Math, RegExp and Date all work.
There is no import, no async/await and no Promise. Asynchronous work is callbacks (see HTTP and scheduling).
/fkdr script compiled on turns on a faster mode for scripts that do heavy work every frame. If it ever fails, fkdr goes back to the normal mode for the rest of the session and says so in chat.
Threading¶
All script code runs on the client thread. Events, HUD suppliers, scheduled callbacks, HTTP callbacks, command handlers, providers: all of them. You never have to think about threads, and you cannot make one.
The one visible consequence: schedule(fn, 10) will not fire in 10 ms. Callbacks run on the client tick, so the resolution is 50 ms.
Do not touch the world from top-level code
Scripts first load while the game starts, before the world exists. Do world work in onLoad or later, and keep top-level code to itself.