Events
chart.transform
Payload: ChartTransformEvent
Asks your mod to transform the chart of a play that is about to start. The payload is { id }: the id of the chartTransform modifier (declared by gameplay.register) that the player switched on. It is delivered during play preparation, never during the play, and only to the mod that owns the modifier, once per switched-on modifier, in load order; the notes a handler leaves are the ones the next modifier is offered.
Inside the handler, and only there, chart.getNotes and chart.setNotes work. A mod that has no handler for the event, whose handler throws, runs too long or runs out of memory has its modification dropped with a notice; the other modifiers and the map are untouched. A handler that never calls chart.setNotes changes nothing. Check request.id when the mod declares several modifiers.
ctx.on("chart.transform", (request) => {
if (request.id !== "rotate") return;
const notes = chart.getNotes();
chart.setNotes({ startUs: notes.startUs, endUs: notes.endUs, column: notes.column.map((value) => (value + 1) % notes.keys), kind: notes.kind });
});
controls.action
Payload: ModActionEvent
A key the player bound to one of the mod's controls.register actions was pressed (pressed: true) or released, with its song time. Delivered only to the mod that registered the action, only while a play runs (never in the map editor), and an action the mod withdrew is ignored. id is the action's own id, not the namespaced binding.
ctx.on("controls.action", ({ id, pressed, timeUs }) => {
if (id === "mark" && pressed) storage.set({ key: "mark", value: timeUs });
});
elements.configure
Payload: ElementConfigure
Delivered to the provider of an element, when another package or the player sets options on it. A package declares an element in provides.elements; a package that lists the provider in uses calls ctx.element("<provider>/<element>").configure(options); the host checks the options against the declaration and hands the result to the provider as this event. Only the provider receives it, never the caller.
Payload: element is the element's name in the provider's provides.elements (without the provider prefix), from the id of the package that configured it, or player when the player's own values from the game's settings apply, and options every declared option: the value set, else the player's, else the declared default (an option with none of these is left out). The player's values win over a package's, and the latest package wins over earlier ones; options the player set that the declaration refuses are ignored.
It fires after each configure call and when the player's values change, and once after the provider's setup for options set before it ran, so register the handler in setup and build the element from the payload. It also fires when a configuring skin is replaced at a map launch, with the options the other packages and the player leave. Without a configuration, the provider receives no event: use the declared defaults until one arrives. If the provider is absent, configure does nothing and the event never fires.
ctx.on("elements.configure", (configure) => {
if (configure.element === "accuracy") log.info(`options from ${configure.from}: ${JSON.stringify(configure.options)}`);
});
game.beat
Payload: Beat
The song clock reached a beat of the chart's timing points. index counts beats from the first timing point across tempo changes (negative before it), timeUs is the beat's song time, bpm the tempo of its timing point and meterBeat its position in the measure (0 on the downbeat; measures restart at each timing point). One event per beat, delivered when the clock reaches it; a late mod thread skips beats rather than delivering a burst. Nothing fires while paused or for a chart without timing points. Delivered to every running script.
ctx.on("game.beat", (beat) => {
if (beat.meterBeat === 0) log.info(`downbeat ${beat.index} at ${beat.bpm} BPM`);
});
game.judgement
Payload: JudgementEvent
One note was judged. column is the lane, timeUs the song time of the judgement, offsetUs the input time minus the note time (the hold end for a release; 0 for a miss), tier a reference to the tier (index, id, name, color), and combo, counts (per tier, miss last) and accuracy (percent) are the totals after this judgement. Fires for every judgement of the play, so keep the handler short (30 ms budget). The queue between the game and scripts holds 1024 events and drops the newest when it is full: a script that must not lose anything reads game.hits or game.player instead. Delivered to every running script.
ctx.on("game.judgement", (judgement) => {
if (judgement.tier.index === 0) log.info(`perfect on lane ${judgement.column}, ${judgement.offsetUs / 1000} ms`);
});
game.lobbyLive
Payload: LobbyLiveEvent
The player's live standing in a multiplayer lobby round, sent only while a lobby play runs and only when the figures changed. rank is the place by live accuracy (1 leads, a tie shares the better place), players the number of players of the round, accuracy the player's own (percent) and rival the player they are compared with, or null when nobody else plays: name (24 characters at most), accuracy, rank, gap (the player's accuracy minus theirs, in points: positive when ahead) and chosen (picked on the lobby page, otherwise the default rival). Everything but the player's own accuracy is declared by the other games, so it never ranks anything. Read-only host data, never a network read from the script.
ctx.on("game.lobbyLive", (live) => {
log.info(`#${live.rank}/${live.players}${live.rival ? `, gap ${live.rival.gap.toFixed(2)}` : ""}`);
});
game.pause
Payload: SongTime
The play was paused. Payload timeUs, the song time. The song clock stops with it, so game.tick and game.beat stop too. Delivered to every running script.
ctx.on("game.pause", ({ timeUs }) => log.info(`paused at ${timeUs} µs`));
game.pauseMenu
Payload: PauseMenuState
The pause menu changed: it opened, the selection moved or a value changed. rows lists the rows shown (continue, restart, quit, volume, and in a watched replay swap, seekBack, seekForward, speed), selection is the index of the highlighted one, volume the music volume (0 to 1) and rate the replay speed (0.25 to 2; 1 outside a watched replay). A mod that draws the pause menu rebuilds its nodes on each event; row labels come from hud.text label bindings, translated by the game.
ctx.on("game.pauseMenu", (menu) => {
log.info(`row ${menu.selection}: ${menu.rows[menu.selection]}`);
});
game.playfieldChange
Payload: Playfield
The playfield moved or resized (window resize, layout change). The payload is the new Playfield, as game.playfield() returns it. Redraw anything you positioned from lanes, sides or hitY. Delivered to every running script.
ctx.on("game.playfieldChange", (field) => {
log.info(`${field.keys} lanes, hit line at ${field.hitY}`);
});
game.resume
Payload: SongTime
The play resumed, or the pause menu closed (a closed menu is announced as a resume, not as a game.pauseMenu). Payload timeUs, the song time. The clock, ticks and beats start again.
ctx.on("game.resume", ({ timeUs }) => log.info(`resumed at ${timeUs} µs`));
game.settingsChange
Payload: ModSettings
The player changed a setting scripts can read: the payload is the full ModSettings (volume, showFps, scrollTimeMs, audioOffsetMs, ratingSystem). It is also sent once at startup, before any play. Delivered to every running script.
ctx.on("game.settingsChange", (settings) => {
log.info(`scroll time ${settings.scrollTimeMs} ms`);
});
game.songEnd
Payload: SongEndEvent
The play finished or the player left it. counts per tier (miss last), maxCombo and accuracy (percent) are the replay's result when the chart finished, the live totals when aborted is true. Delivered once per play to every running script; game.player().playing is false afterwards.
ctx.on("game.songEnd", (end) => {
if (!end.aborted) storage.set({ key: "last", value: end.accuracy });
});
game.songStart
Payload: SongStartEvent
A chart starts playing. Payload: the song, the judgements (also game.judgements()), the playfield of this play, versusCentre (the width, in screen heights, a side-by-side comparison keeps free between its two playfields; unused in solo) and timeUs, the song time playback begins at (negative during a lead-in). Delivered once per play to every running script: the skin, the map script and the mods. From then on game.notes, game.playfield, game.judgements and the playfield.* live calls work. Drop the state of the previous play here (counters, nodes you built per play).
ctx.on("game.songStart", (start) => {
log.info(`${start.song.title}: ${start.judgements.tiers.length} tiers, starts at ${start.timeUs} µs`);
});
game.tick
Payload: TickEvent
A heartbeat while the song clock runs: 30 per second by default. Payload timeUs (song time) and hitCount, the number of real, non-miss hits of the play read from the native history (so it is exact even when game.judgement events were dropped). Use it to poll game.hits, game.keys or game.player only when hitCount changed. Ticks stop while paused, a tick that is late is skipped rather than delivered in a burst, and a handler that is slower than the interval just gets later ticks. Offline video exports deliver one tick per frame.
let seen = 0;
ctx.on("game.tick", ({ hitCount }) => {
if (hitCount === seen) return;
seen = hitCount;
const last = game.hits({ limit: 1 })[0];
if (last) log.info(`last hit ${last.offsetMs.toFixed(1)} ms`);
});
leaderboard.result
Payload: LeaderboardResult
The answer to leaderboard.query or leaderboard.best. requestId is the number the function returned; match it, because a mod may have two requests outstanding. The payload carries the page (chartId, offset, total of the whole ranking, entries), the judgement name the ranking was evaluated under, the performance calculator and unit when the ranking has one, unavailableReplays (recorded plays whose replay could not be read or judged again; they are not in total) and error, an English message when no ranking could be built (total is then 0 and entries empty).
It is delivered only to the mod that asked, from the mods thread, under the mod's usual budget. It arrives once per accepted request, in no guaranteed order against other requests. A mod that was disabled or unloaded meanwhile, or a host that was replaced, never receives it: the request is forgotten.
ctx.on("leaderboard.result", (result) => {
if (result.error) log.warn(result.error);
else log.info(`${result.total} plays, ${result.entries.length} listed under ${result.judgement}`);
});
Triggered by leaderboard.query and leaderboard.best.
library.chartAdd
Payload: ChartAdded
A chart was added to the library by an explicit scan (a pack was installed, the player scanned a folder). The payload is { chartId }, a library chart id as used by leaderboard.query, ratings.backfill and your tables. It is delivered after the scan's transaction committed, once per added chart, to every running script that subscribed. An explicit scan that adds thousands of charts sends thousands of events: prefer library.chartsAdded for batch work. It is sent after library.chartsAdded of the same scan.
ctx.on("library.chartAdd", (added) => log.info(`chart ${added.chartId} added`));
library.chartsAdded
Payload: ChartsAdded
The charts one scan added, in a single event. chartIds holds up to 8192 ids; truncated is true when the scan added more, in which case chartIds has only the first 8192 and a mod that wants every chart asks for a whole-library ratings.backfill (without charts). It is delivered after the scan's transaction committed, to every running script that subscribed, before the per-chart library.chartAdd events of the same scan. An empty scan sends nothing.
ctx.on("library.chartsAdded", (added) => {
ratings.backfill(added.truncated ? { id: "prismcalc-1" } : { id: "prismcalc-1", charts: added.chartIds });
});
The ids can be passed straight to charts of ratings.backfill.
library.ready
Payload: LibraryReady
Asks the mods to run their whole-library check: the menu has loaded and the library can be queried. The payload is empty ({}). It is delivered to every running script that subscribed, and more than once per session: when the interface (re)loads, after a global library scan, when the mods restart, and when the player presses "Recalculate ratings". A handler must therefore be idempotent. It is the usual moment for a whole-library ratings.backfill, which only calculates the charts that lack a current row.
ctx.on("library.ready", () => {
ratings.backfill({ id: "prismcalc-1" });
});
metron.performanceResult
Payload: PerformanceResult
The answer to metron.performance. requestId is the number the function returned. calculator is the id asked for, value the performance (null when it failed), unit is pp, or SSR for etterna-515, and error is the English reason when value is null. It is delivered only to the mod that asked.
The result is bound to the play it was asked in: if the song changed before the calculation finished, the result is dropped and no event arrives. Do not wait for it forever; ask again in the next play.
ctx.on("metron.performanceResult", (result) => {
if (result.error) log.warn(result.error);
else log.info(`${result.calculator}: ${result.value} ${result.unit}`);
});
Triggered by metron.performance.
playfield.noteMask
Payload: NoteMaskEvent
Asks your mod for the covers and the lift of a play that is about to start. The payload is { id, params }: the id of the noteMask modifier (declared by gameplay.register) the player switched on, and the value of every parameter that modifier declared in params, by id: the player's saved value clamped to the declared min and max, or the declared default when the player never changed it. An id the mod did not declare never appears. It is delivered during play preparation, never during the play, and only to the mod that owns the modifier, once per switched-on modifier, in load order.
Inside the handler, and only there, playfield.setNoteMask works. A mod that has no handler for the event, whose handler throws, runs too long or runs out of memory has its modification dropped with a notice; the other modifiers and the play are untouched. A handler that never calls playfield.setNoteMask changes nothing. Check request.id when the mod declares several modifiers.
ctx.on("playfield.noteMask", (request) => {
if (request.id !== "lift") return;
playfield.setNoteMask({ lift: request.params.liftHeight });
});
See Setting the playfield mask.
ratings.progress
Payload: RatingProgress
A progress report of a ratings.backfill request, delivered only to the mod that made it. requestId is the number the function returned and id the rating's id. done charts were calculated of total (the charts that lacked a current row when the request started), failed of them unavailable. finished is true on the last report, after which no more arrive for that request; error is set when the whole request failed. ahead is the number of calculations waiting before this request in the library's one queue (0 once it runs); done and total stay 0 until it starts.
Several reports arrive per request, so check finished before starting the next backfill. A report that arrives after the request was closed (the mod was stopped) is not delivered. The game shows the same progress in its processing window without any code from the mod.
ctx.on("ratings.progress", (progress) => {
if (progress.finished) log.info(`${progress.id}: ${progress.done}/${progress.total}, ${progress.failed} failed`);
});
Triggered by ratings.backfill.
skinImport.action
Payload: SkinImportAction
The player pressed a button of your import panel. The payload is { id }, the id of the action you declared in skinImport.panel. It is delivered only to the mod that owns the panel. dismiss is the game's own button: the game closes the panel itself and the event is not delivered for it. Actions that carry editSkin open that skin in the editor and are not delivered either. Everything else reaches you, in the order the player presses them.
ctx.on("skinImport.action", (action) => {
if (action.id === "retry") skinImport.panel({ title: "Retrying", status: "working" });
});
skinImport.created
Payload: SkinImportCreated
The answer to skinImport.create. requestId is the number the function returned; id is the folder name of the new skin, which may differ from the id you asked for (a suffix such as -2 is added when the name was taken), and error is the reason when the folder could not be written or failed the inspection a skin goes through. It is delivered only to the mod that asked, and only if the player has not closed the panel or picked another source meanwhile: a stale answer is dropped.
ctx.on("skinImport.created", (created) => {
if (created.error) skinImport.panel({ title: "Failed", status: "error", detail: created.error });
});
Triggered by skinImport.create.
skinImport.opened
Payload: SkinImportOpened
The player picked a source for one of your importers and the native worker read it. The payload is importerId (which of your importers), locale (the interface language, en, fr, zh or ko, for the panel's texts), and source or error. source describes what was read: sourceId (give it to skinImport.stage), label, kind (folder or archive), the parsed ini (general fields, mania sections), the images with their sizes and frames, truncated, totalBytes and problems. error is set instead when the source could not be read.
It is delivered only to the mod that owns the importer, once per pick. A new pick replaces the previous source and preparation; an answer that arrives after the panel was closed is dropped. The game opens the dialog: the mod never sees a path.
ctx.on("skinImport.opened", (opened) => {
if (opened.error || !opened.source) return;
log.info(`${opened.source.images.length} pictures in ${opened.source.label}`);
});
skinImport.staged
Payload: SkinImportStaged
The answer to skinImport.stage. requestId is the number the function returned. On success stageId names the preparation for skinImport.create and report lists the generated files, totalBytes, budgetBytes (900 KiB), overBudget and problems; otherwise error says why. It is delivered only to the mod that asked, and a stale answer (panel closed, another source picked) is dropped. Only the latest preparation can be created.
ctx.on("skinImport.staged", (staged) => {
if (staged.report?.overBudget) log.warn(`${staged.report.totalBytes} bytes, over the budget`);
});
Triggered by skinImport.stage.
ui.action
Payload: PopupActionEvent
A button of the mod's ui.popup was clicked. id is the action's id, or dismiss when the player closed the popup with its own button (the popup is already removed then). Delivered only to the mod that owns the popup.
ctx.on("ui.action", ({ id }) => {
if (id === "cancel") ui.dismiss();
});
Defined elsewhere
ChartTransformEvent (declarations), ModActionEvent (declarations), ElementConfigure (declarations), Beat (declarations), JudgementEvent (declarations), TierRef (declarations), LobbyLiveEvent (declarations), LobbyRival (declarations), LobbyCoopLive (declarations), SongTime (declarations), PauseMenuState (declarations), PauseMenuRow (declarations), Playfield (declarations), Lane (declarations), PlayfieldSide (declarations), ModSettings (declarations), SongEndEvent (declarations), SongStartEvent (declarations), Song (declarations), BpmRange (declarations), TimingPoint (declarations), JudgementConfig (declarations), TierInfo (declarations), TickEvent (declarations), LeaderboardResult (declarations), LeaderboardEntry (declarations), TierCount (declarations), LeaderboardPerformance (declarations), ChartAdded (declarations), ChartsAdded (declarations), LibraryReady (declarations), PerformanceResult (declarations), NoteMaskEvent (declarations), RatingProgress (declarations), SkinImportAction (declarations), SkinImportCreated (declarations), SkinImportOpened (declarations), SkinSource (declarations), SourceKind (declarations), SkinIni (declarations), IniGeneral (declarations), ManiaSection (declarations), ManiaColumn (declarations), SourceImage (declarations), PixelBox (declarations), IniSection (declarations), IniEntry (declarations), SourceFile (declarations), SkinImportStaged (declarations), Report (declarations), StagedFile (declarations), PopupActionEvent (declarations)