Registration — registerMode / unregisterMode
Stability: Stable.
The entry point for every mode. A mode resource builds a plain-data
descriptor and registers it with the SDK
(exports.sdk:registerMode), which the engine mirrors and runs.
exports.sdk:registerMode(def)
Registers a mode. Call it from your mode resource once the SDK has started.
CreateThread(function()
while GetResourceState('sdk') ~= 'started' do Wait(100) end
exports.sdk:registerMode(MODE)
end)| Parameter | Type | Required | Notes |
|---|---|---|---|
def | table | yes | The mode descriptor. Must have a unique def.id. |
Validation
The descriptor is validated before it is accepted (Sdk.validateMode). A
plain-data mode otherwise fails silently at runtime — a mistyped role spawns
players into the void, an unknown driver leaves them frozen on
"Waiting for players…". Validation turns those into a clear console diagnostic.
-
Errors refuse the mode. If anything is structurally wrong, the mode is not registered and every problem is printed:
[sdk] mode koth REFUSED -- 2 error(s): [sdk] - `teamCount` must be an integer >= 2 (the number of teams) [sdk] - `rules.win` is required -- one of { roundWins=N } | { score=N } | { timeLimit=S } -
Warnings are logged but allowed (e.g. a
drivernot registered yet, noteamCountfor a teamless mode, an unpinnedapiVersion). -
What's checked:
id/types/enums (queue),apiVersionvs the SDK,teamCount(integer ≥ 2; only 2 supported today),minToStart ≤ perTeam, numerictimings,armor/loadoutshapes, and the fullrulesblock (structure, phases, score, win, zones). Game-design choices (round counts, kill limits, …) are never second-guessed. Arena spawn coverage is checked by the engine at consume time (an arena block with fewer entries than yourteamCountlogs a warning).
Behaviour
-
The SDK tags the descriptor with the calling resource (
def.resource = GetInvokingResource()), so it can drop the mode if that resource stops. -
Missing fields are filled with defaults at registration time:
Field Default applied perTeam1minToStart1maxRound-1timings{}teamCount2(only whenrulesis present)Other fields (e.g.
rules,driver,label,respawns) are not defaulted here — behaviour resolves at tick time (tick>rulesruntime > nameddriver) andrules/phase keys fall back inside the runtime. See Mode descriptor for the full default table. -
Registering an
idthat already exists overwrites the previous descriptor. -
On success the SDK prints:
[sdk] mode registered: <id> (<label>) from <resource>
Registering the same def table more than once is harmless (it just
re-registers the same id). Register each mode once, after the SDK is started.
exports.sdk:unregisterMode(id)
Removes a mode by id. After this, the mode no longer appears in the lobby and players can no longer join it. Existing scenes of that mode are not torn down by this call — they drain as players leave.
exports.sdk:unregisterMode('mygame')| Parameter | Type | Required | Notes |
|---|---|---|---|
id | string | yes | The id of a registered mode. Unknown ids are a no-op. |
Automatic cleanup
You usually don't need unregisterMode. When a mode's owning resource stops,
the SDK automatically unregisters every mode tagged with that resource, so a
stopped mode can never have its hooks invoked again. Restarting your mode
resource re-runs your registration thread and re-registers it.
See also
- Mode descriptor — every field you can put in
def. - Hooks — optional functions you can add to
def. - Getting started — the full scaffold.