Functions
leaderboard.best
function leaderboard.best(input: LeaderboardBestQuery): number | null;
The first entry of a chart's local leaderboard: the same as leaderboard.query with limit 1. It takes an object, { chartId }, not a bare number. It returns a request number or null under the same limits as leaderboard.query (the two share the 2 and 16 outstanding requests), and the answer arrives as a leaderboard.result event whose entries hold at most one play.
leaderboard.best({ chartId: 12 });
ctx.on("leaderboard.result", (result) => {
const best = result.entries[0];
if (best) log.info(`best: ${best.accuracy.toFixed(2)}% by ${best.playerName ?? "unknown"}`);
});
The errors are those of leaderboard.query.
leaderboard.query
function leaderboard.query(input: LeaderboardQuery): number | null;
Reads the local leaderboard of a chart: the plays of this computer, each replay judged again with the player's current judgement and ranked like the Leaderboard tab. Only mods call it, from setup or an event handler. It returns a request number, or null when the limit is reached (2 requests outstanding per mod, 16 in total). It never blocks: the answer arrives as a leaderboard.result event with the same requestId, only in the mod that asked.
chartId is the library's chart id (as in library.chartAdd, library.chartsAdded and the chart tables), a positive integer; a mod has no file path. limit is 1 to 100 (20 by default) and offset 0 to 100000 (0 by default). The result carries total, entries (rank, player name, accuracy in percent, performance, combo, misses, tier counts, rate, whether the play was modified, date in milliseconds), the judgement used, the calculator's performance unit, and error when it failed.
const requestId = leaderboard.query({ chartId: 12, limit: 10 });
ctx.on("leaderboard.result", (result) => {
if (result.requestId !== requestId || result.error) return;
for (const entry of result.entries) log.info(`#${entry.rank} ${entry.accuracy.toFixed(2)}%`);
});
Errors you will see: chartId must be a library chart id (a positive integer), limit must be between 1 and 100, offset must be at most 100000, only mods read the local leaderboard, local scores are unavailable.
tabs.extend
function tabs.extend(input: TabExtensionDeclaration): void;
Adds sections to one of the host's tabs without replacing what it shows: tab is info, leaderboard or mods (Training and the editor stay closed), slot puts your panels before (top) or after (bottom) the host's content. Only mods call it, only from setup. Panels are the same as for tabs.register, but 1 to 4 per extension. order (0 to 1000) sorts the sections of the same tab and slot; equal orders sort by mod id.
A mod extends the host's tabs at most 4 times, and all mods together at most 24 extensions are shown (extras are dropped).
tabs.extend({
tab: "info",
slot: "bottom",
order: 0,
panels: [{ kind: "text", title: "Note", text: "Rated by my calculator." }],
});
Errors you will see: tabs.extend is only available in a mod's setup, a mod extends the host's tabs at most 4 times, panels must hold 1 to 4 panels, panel text must not contain control characters.
tabs.register
function tabs.register(input: TabDeclaration): void;
Adds a tab next to Info, Leaderboard and Mods in the panel of the selected chart in song select. Only mods call it, only from setup. The tab is published as <modId>/<id>. A tab is a list of declarative panels (1 to 8): metrics, bars, radar, timeline, leaderboard (the best plays of the chart) and text. The game draws them; there is no script code in the interface.
A field reads a numeric column of a rating of your mod ({ kind: "column", rating, column }, the rating registered before in the same mod), a neutral chart metric, or a leaderboard statistic (plays, bestPerformance, bestAccuracy). Tabs sort by order (0 to 1000), then by key, after the host's own tabs.
| Limit | Value |
|---|---|
| Tabs per mod / all mods | 4 / 12 (extras are dropped) |
id |
a-z, 0-9, -, 1 to 32 characters |
title |
1 to 24 characters |
icon |
one of 16: layers (default), info, trophy, star, gauge, activity, chart-bar, list, flame, music, clock, target, sparkles, bookmark, heart, users |
| Panels | 1 to 8; title up to 64 characters; text up to 280; a leaderboard panel lists 1 to 10 plays |
tabs.register({
id: "stats",
title: "Stats",
icon: "chart-bar",
order: 10,
panels: [
{ kind: "metrics", title: "Chart", fields: [
{ label: "Notes", source: { kind: "chart", metric: "notes" } },
{ label: "Plays", source: { kind: "leaderboard", stat: "plays" } },
] },
{ kind: "leaderboard", title: "Top plays", limit: 5 },
],
});
Errors you will see: tabs.register is only available in a mod's setup, tab `x` is registered twice, a mod registers at most 4 tabs, tab icon "x" is not an allowed icon, panels must hold 1 to 8 panels, a leaderboard panel lists 1 to 10 plays, order must be between 0 and 1000, field `Overall` reads column `overall` of rating `r`: register that rating first (`ratings.register`, same mod) and name one of its numeric columns. See Tabs and the local leaderboard.
Types
Definitions read from the SDK. A type used here that is defined on another page is listed under Defined elsewhere.
type LeaderboardBestQuery = { chartId: number; };
type LeaderboardQuery = {
chartId: number;
limit?: number | null;
offset?: number | null;
};
type TabExtensionDeclaration = {
tab: ExtendableTab;
slot: TabSlot;
order?: number;
panels: TabPanel[];
};
type ExtendableTab = "info" | "leaderboard" | "mods";
type TabSlot = "top" | "bottom";
type TabPanel = { kind: "metrics"; title: string; fields: TabField[]; } | { kind: "bars"; title: string; fields: TabField[]; max?: number | null; } | { kind: "radar"; title: string; fields: TabField[]; max?: number | null; } | { kind: "timeline"; title: string; series: RatingSeries[]; } | { kind: "leaderboard"; title: string; limit: number; } | { kind: "text"; title?: string | null; text: string; };
type TabField = {
label: string;
source: TabFieldSource;
unit?: string;
decimals?: number;
};
type TabFieldSource = { kind: "column"; rating: string; column: string; } | { kind: "chart"; metric: ChartMetric; } | { kind: "leaderboard"; stat: LeaderboardStat; };
type LeaderboardStat = "plays" | "bestPerformance" | "bestAccuracy";
type TabDeclaration = {
id: string;
title: string;
icon?: string | null;
order?: number;
panels: TabPanel[];
};
Defined elsewhere
ChartMetric (ratings), RatingSeries (ratings), RatingSeriesSource (ratings)