Skip to content

ScriptingLifecycle

All optional, all top-level functions.

function when
onLoad() once, at load. Declare settings, commands and HUD entries here.
onEnable() the module was switched on
onDisable() switched off
onReset() world change. Clear per-game state here.
onUnload() the script is being reloaded or removed. Release anything you hold.
var count = 0;

function onLoad() {
    settings.bool('Alert', true);
    hud.add('main', 'Bed Alert', function () { return '§bbeds §f' + count; });
}

function onReset() {
    count = 0;       // a new game, a new count
}

function onUnload() {
    // hud entries, events, schedules and commands are removed for you
}

onReset is the one people forget

It is why ported scripts leak state between games: without it, whatever your script accumulated during one match is still there in the next one.

If onLoad throws, the script is marked broken and disabled. Its declarations only half ran, so there is nothing coherent left to run.

Everything a script registers (events, HUD entries, commands, schedules, providers) is removed when it reloads or unloads. You do not need to clean those up in onUnload; use it for state of your own.