Errors and the sandbox¶
When a script goes wrong¶
fkdr reports the error, and a script that keeps failing is switched off.
- A parse error or a throw at load disables the script, prints the message with the file and line to chat, and paints its name red in the menu.
- A file named after an existing module is refused before any of its code runs. It appears in
/fkdr scriptand inerrorsas broken, with the clash named; rename the file and reload. - A throw inside a handler is printed and counted. After five, the script is switched off and says so, because a handler throwing twenty times a second floods the log, costs frames, and buries the first error, which was the only one worth reading.
- A refusal (an
httpcall to afile://URL, a command name somebody else owns) is printed but does not count towards that five: the API answering "no" is not a crash. - An infinite loop is killed after 2.5 seconds by a watchdog, and lands in the script's error list like any other failure. Without it, one bad loop is a frozen client and a force-quit.
/fkdr script errorsreprints the last error for every script.- Switching a broken script back on in the menu clears its failure count.
The sandbox¶
Scripts run in a safe box. They can use the API on these pages and ordinary JavaScript, and nothing else. What they cannot reach has a safe way in instead:
| not allowed | use instead |
|---|---|
| opening files | storage |
| network connections | http |
| threads and running programs | schedule, scheduleTicks |
| the game's own code | player, world, render |
| fkdr's own code | the API on these pages |
The built-in JavaScript objects (Array.prototype and friends) cannot be changed, so one script cannot change the language out from under another.
Read scripts before you run them
The sandbox means a script you have not read cannot quietly read your licence key or change your mods. Still, read scripts before you run them.