Mods and skins do not call each other. A package that wants to be placed, resized or recolored by others declares an element with typed options; another package, or the player, sets those options, and the host delivers them to the provider, which redraws. Each package keeps its own engine and its own budget. This is how the whole default HUD works: the default skin builds no hud.* node, it only places the elements of the HUD mods.
This page covers the provider side, the user side, the dependencies between packages, the persistent storage.*, and what a reload keeps. You should know how to build a HUD element first.
A complete provider
This mod, example.counter, provides the element counter: a combo counter with a label, the accuracy, the last judgement and the best combo ever reached, which it keeps in its storage. It declares ten options and redraws from them.
/// <reference path="../../../mods/sdk/modding.d.ts" />
// A combo counter that others configure. The mod PROVIDES an element, `counter`, with
// declared options; a skin, another mod or the player places and colors it without any
// script calling another. It receives the options in `elements.configure` and draws the
// element from them. The best combo is kept in the mod's storage, so it survives the
// game being closed. `counter-placer` is a mod that configures this element.
//
// Install it by copying this folder into the mods folder (Mods page → Open folder).
/** Everything the element accepts: `configure` refuses an unknown option or a value out of bounds. */
const OPTIONS = {
x: { type: "number", min: 0, max: 1, default: 0.5, label: "Horizontal position" },
y: { type: "number", min: 0, max: 1, default: 0.08, label: "Vertical position" },
anchor: { type: "enum", values: ["topLeft", "top", "topRight", "left", "center", "right", "bottomLeft", "bottom", "bottomRight"], default: "top", label: "Anchor" },
size: { type: "number", min: 0.01, max: 0.3, default: 0.06, label: "Size" },
visible: { type: "boolean", default: true, label: "Show the counter" },
textColor: { type: "color", default: "theme:text", label: "Combo color" },
label: { type: "string", maxLength: 24, default: "Combo", label: "Label" },
showBest: { type: "boolean", default: true, label: "Show the best combo" },
decimals: { type: "integer", min: 0, max: 4, default: 0, label: "Accuracy decimals", player: true },
judgementColors: { type: "colors", default: {}, label: "Judgement colors by tier" },
} satisfies Record<string, ElementOption>;
type Options = {
x: number; y: number; anchor: Anchor; size: number; visible: boolean; textColor: string;
label: string; showBest: boolean; decimals: number; judgementColors: Record<string, string>;
};
/** The declared defaults, until someone configures the element. */
const declared: Record<string, ElementOption> = OPTIONS;
let options = Object.fromEntries(Object.entries(declared).map(([name, option]) => [name, option.default])) as Options;
let playing = false;
let best = 0;
function build() {
hud.remove("counter");
if (!playing || !options.visible) return;
hud.group({
id: "counter",
flow: { direction: "column", align: "center" },
layout: { x: options.x, y: options.y, anchor: options.anchor },
});
hud.text({
id: "counter-label", parent: "counter", text: options.label,
style: { size: options.size / 3, color: options.textColor, label: true },
});
hud.text({
id: "counter-value", parent: "counter", text: "0", bind: { kind: "combo" },
animate: { on: "hit", kind: "pop", durationMs: 120 },
style: { size: options.size, weight: 700, color: options.textColor, face: "num" },
});
hud.text({
id: "counter-accuracy", parent: "counter", text: "", bind: { kind: "accuracy", decimals: options.decimals },
style: { size: options.size / 3, color: options.textColor, face: "num" },
});
hud.text({
id: "counter-judgement", parent: "counter", text: "", bind: { kind: "lastJudgement", colors: options.judgementColors },
animate: { on: "judgement", kind: "popOut", durationMs: 500 },
style: { size: options.size / 2.5, weight: 600 },
});
if (options.showBest) {
hud.text({
id: "counter-best", parent: "counter", text: `Best ${best}`,
style: { size: options.size / 3, color: options.textColor, opacity: 0.7 },
});
}
}
export default defineMod({
id: "example.counter",
name: "Configurable counter",
version: "1.0.0",
apiVersion: 2,
author: "Prism",
description: "A combo counter whose position, size and colors other packages and the player set.",
// `root` names the HUD node the skin editor finds on screen; only the id is checked.
provides: { elements: { counter: { root: "counter", options: OPTIONS } } },
setup() {
// Storage is read in `setup` or in a handler, never while the file loads.
const saved = storage.get("best-combo");
best = typeof saved === "number" ? saved : 0;
ctx.on("elements.configure", (configure) => {
if (configure.element === "counter") {
options = configure.options as Options;
build();
}
});
ctx.on("game.songStart", () => {
playing = true;
build();
});
ctx.on("game.songEnd", (end: SongEndEvent) => {
playing = false;
hud.clear();
if (!end.aborted && end.maxCombo > best) {
best = end.maxCombo;
storage.set({ key: "best-combo", value: best });
}
});
},
});
Until someone configures the element, the mod works with the declared defaults: that is why it starts from them. After that, every change reaches elements.configure with all the options, so the handler only has to replace its options and rebuild.
The mod that configures it
A user declares the provider in uses, checks it is there with ctx.has, and configures the element. It draws nothing itself.
/// <reference path="../../../mods/sdk/modding.d.ts" />
// Places and colors the `counter` element of `example.counter` (the folder
// `configurable-counter`), without a single `hud.*` call. It declares the package in
// `uses`; if the player removed or disabled it, `ctx.has` is false and nothing happens.
//
// Install both folders by copying them into the mods folder (Mods page → Open folder).
export default defineMod({
id: "example.counter-placer",
name: "Counter placer",
version: "1.0.0",
apiVersion: 2,
author: "Prism",
description: "Moves the configurable counter to the right and colors it.",
// Optional by default: without the package this mod still loads.
uses: { "example.counter": "^1" },
setup() {
if (ctx.has("example.counter")) {
// The options are checked against the provider's declaration: an unknown option,
// a wrong type or a value out of bounds throws here, in this script.
ctx.element("example.counter/counter").configure({
x: 0.98,
y: 0.4,
anchor: "topRight",
size: 0.07,
textColor: "#ffd27a",
label: "Streak",
judgementColors: { "0": "#66ccff", "1": "#88ff88" },
});
}
},
});
Copy both folders (configurable-counter and counter-placer) into your mods folder (Mods page, Open folder). The counter appears on the right. Remove counter-placer and it goes back to the middle of the top: those are the defaults.
Declaring an element
provides: { elements: { <name>: { root?, options } } } in defineMod or defineSkin.
rootis theidof the root node of the element in your HUD tree. The skin editor uses it to find the element on screen. Only the id is checked: the node does not have to exist when you declare.optionsmaps option names to declarations. A declaration is{ type, min?, max?, values?, maxLength?, default?, label?, player? }.
The key of an element is "<package id>/<element>": example.counter/counter. Players' settings and ctx.element use it.
Option kinds
type |
Accepts | Declaration fields |
|---|---|---|
number |
a finite number | min, max |
integer |
a whole number | min, max |
boolean |
true or false |
|
string |
text without control characters, 256 characters at most | maxLength (1 to 256) |
color |
#rgb, #rrggbb, #rrggbbaa, or theme:<role> (a colour token of the active theme: theme:text, theme:accent...) |
|
enum |
one of values |
values (1 to 32 entries of at most 32 characters, no duplicate) |
colors |
an object of colors by key (a tier id, an index...), 64 entries at most, keys of at most 32 characters |
default is the value you receive when nobody sets one; it must satisfy the declaration. An option with no default and no value is left out of the options you receive: read it as optional. label (64 characters at most) is the name shown in the skin editor and in settings.
min and max only exist for numbers, values only for an enum, maxLength only for a string. A hex color does not follow the theme; theme:<role> does.
Names and limits
| What | Rule |
|---|---|
| Element name | 1 to 32 characters among a-z, 0-9 and -, starting with a letter |
| Option name | 1 to 32 ASCII letters and digits, starting with a letter (textColor, not text-color) |
| Elements per package | 16 |
| Options per element | 32 |
label |
64 characters |
feature of a dependency |
64 characters |
An invalid declaration stops the package from loading, with the reason on the Mods page.
Three layers of configuration
The options you receive are always the full set, resolved from three layers. Defaults, then the skin, then the player: the last one wins, and nothing global overrides the player.
- Defaults. The
defaultof each option. - A package. A skin or a mod calls
ctx.element("<package>/<element>").configure({ ... }). The options are checked against your declaration (unknown option, type, bounds: an exception in the calling script), completed with the defaults, and delivered to you after the calling script has run. If several packages configure the same element, the latest wins. A skin's configuration is dropped when the skin is replaced: the element goes back to what the other packages and the player left. - The player. In the skin editor, per skin, the player sets any option of an element it can place, and the host overlays those values on the options of layer 2.
Receiving the options
ctx.on("elements.configure", (configure) => {
// configure.element: the element's name in your provides.elements
// configure.from: the id of the package that configured it, or "player"
// configure.options: every declared option (the user's value or the default)
log.info(`${configure.element} configured by ${configure.from}`);
});
from is "player" when the player's values apply, otherwise the id of the package. The provider always gets every option, never a partial set. A restarting provider (a skin at every map launch, or every mod when the mods reload) receives the last configuration of each user again; you do not have to remember it.
A value of the player that your declaration refuses (an unknown option, a wrong type, out of bounds, an enum value you removed) is ignored and reported in your messages: example.counter/counter: the player's option `size` is ignored: expected a number in [0.01, 0.3], got 5. Values of a provider that is absent or disabled are kept and applied when it runs again.
What the player can change
The skin editor edits every option of an element that has numeric x and y options (a placeable element: positions, sizes, visibility, fonts, colors, decimals...). The player: true flag matters for an element without a place, which the editor cannot place: its player options are listed in Settings, Game, Mods, and stored in the global setting elementOptions, under the skin's configuration. The shipped mods flag the options a player is likely to want (length and mode of hit-bar, always of fps, decimals of accuracy); since those elements have x and y, the skin editor edits them anyway.
const options: Record<string, ElementOption> = {
length: { type: "integer", min: 1, max: 256, default: 50, label: "Hits shown", player: true },
mode: { type: "enum", values: ["last", "all"], default: "all", label: "Hits drawn", player: true },
};
Give every option a label: it is the only text the player sees. Give an element with a font option the element field on its nodes so that the player's hudFonts choice applies (see Build a HUD element).
Using another package
uses: { "<package id>": "<semver range>" } in defineMod or defineSkin: the id of the package and a range ("^1", ">=1.2, <2"). The long form is { version, required?, feature? }. At most 16 packages, and a package cannot use itself.
Optional and required
A dependency is optional by default. When the package is absent, installed in another version, or failed to load, your package still loads, ctx.has("<id>") is false, and the Mods page reads feature "Combo styling" disabled: package pvng.combo missing (feature names what stops working; without it the text reads features using pvng.combo disabled: package pvng.combo missing). The other reasons are package pvng.combo 2.0.0 does not match ^1 and package pvng.combo is not active (disabled or failed).
required: true makes it mandatory: without it your package does not load, and the Mods page reads requires pvng.combo ^1: package pvng.combo missing.
/// <reference path="../../../mods/sdk/modding.d.ts" />
export default defineMod({
id: "example.combo-skin",
name: "Combo styling",
version: "1.0.0",
apiVersion: 2,
uses: {
"pvng.combo": { version: "^1", required: false, feature: "Combo styling" },
"pvng.accuracy": "^1",
},
setup() {
if (ctx.has("pvng.combo")) {
ctx.element("pvng.combo/combo").configure({ x: 0.5, y: 0.2, anchor: "top", showLabel: false });
}
},
});
ctx.has and ctx.element
ctx.has(id) is true when the package is in your uses, compatible and running. ctx.element("<package>/<element>").configure(options) needs the package in uses (add `pvng.combo` to `uses` to configure its elements) and checks options against the provider's declaration. If the provider is missing, configure does nothing and does not throw: the feature is off. Guard with ctx.has anyway when the call depends on it, as the default skin does.
ctx.has and ctx.element exist in map scripts too, but a map script has no uses: has is always false and configure throws declare the package before configuring elements.
Order and cycles
Packages set up after the ones they use; otherwise in load order (see below). A dependency cycle refuses every package of the cycle: dependency cycle: a → b → a. A skin resolves its dependencies at every map launch, against the active mods.
Storage
storage keeps JSON values between sessions, for mods and skins (not map scripts).
| Function | Does |
|---|---|
storage.get(key) |
the stored JSON value, or null |
storage.set({ key, value }) |
stores a JSON value |
storage.remove(key) |
removes a key |
storage.keys() |
the keys, sorted |
storage.clear() |
empties the storage |
const saved = storage.get("best-combo");
const best = typeof saved === "number" ? saved : 0;
storage.set({ key: "best-combo", value: Math.max(best, 120) });
- A mod's storage is the file
mod-storage/<id>.jsonof the game's data folder, chosen by the host from the validated id: a mod cannot read another's. A skin's ismod-storage/skins/<id>.json. - Keys are 1 to 128 characters; a mod holds at most 256 keys. The whole storage (key bytes plus the JSON text of each value) is at most 256 KiB. A value has no limit of its own beyond that total.
- Writes are batched: the file is written at most once per second, through a temporary file renamed over the old one, and once more when the host stops. Uninstalling a mod keeps its storage.
storage.*is not available while the file loads: use it insetupor in a handler.- An unreadable or over-sized file makes
setupfail withstorage <path>: …. - Anything that must survive a restart goes there:
letvariables are lost.
Load order, fonts and images
These manifest fields shape a package that provides elements.
| Field | Meaning |
|---|---|
loadOrder |
0 to 10000, 1000 by default. Mods set up by (loadOrder, id) after the packages they use. The game's own mods/ load before the player's. HUD layers stack in that order: a later mod draws above an earlier one. The shipped HUD widgets use 300 to 400 |
fonts |
up to 8 fonts the package bundles: { name: "fonts/File.ttf" }; used by style.font as <package>/<name>, which another package can name too (see Fonts) |
images |
up to 64 .png paths decoded for the native stage (see Native rendering); the PNGs of hud.image do not need to be listed |
Reloads and state
The Reload button of the Mods page restarts the whole mods host: every package runs its top level and its setup again, and module variables are lost. It is refused during a play ("Mods cannot be reloaded during a play").
What you get back after a restart: the configurations that users set on your elements (re-delivered as elements.configure), and your storage. What you do not: your own variables. Rebuild from elements.configure and from storage.get in setup.
ctx.hot (data, save, dispose), ctx.off, and the setTimeout and setInterval of manivelle:env are in the SDK because it declares the engine's whole context. Do not rely on them: the game does not reload one script in place, so ctx.hot has nothing to carry, and nothing advances the timers, so a callback given to setTimeout never runs. Drive time from events (game.tick, game.beat).
Errors you will see
| Message | Cause |
|---|---|
add `example.counter` to `uses` to configure its elements |
ctx.element of a package missing from uses |
`example.counter` provides no element `bar` |
an element name the provider does not declare |
example.counter/counter: unknown option `colour`, expected one of anchor, decimals, ... |
an option name that is not declared |
example.counter/counter: option `size`: expected a number in [0.01, 0.3], got 5 |
a value out of the declaration (type, bounds, enum) |
elements are named "<package>/<element>", got "counter" |
ctx.element without the package prefix |
`uses` names 17 packages; the limit is 16 |
too many dependencies |
a package cannot use itself |
uses names its own id |
dependency cycle: a → b → a |
packages that use each other |
`uses.x`: "one" is not a semver range: … |
an invalid version range |
feature "X" disabled: package Y missing |
an optional dependency is absent (a notice, the package runs) |
package Y 2.0.0 does not match ^1 / package Y is not active |
the other reasons of that notice |
requires Y ^1: package Y missing |
a required dependency is absent (the package does not load) |
`provides.elements` declares 17 elements; the limit is 16 |
too many elements |
element `counter` declares 33 options; the limit is 32 |
too many options |
element name "Counter" must be 1 to 32 characters starting with a letter |
an invalid element name |
`min` and `max` only apply to numbers |
min or max on a non-number |
an enum needs 1 to 32 values |
an empty or oversized enum |
element `counter`, option `size`: default: expected a number in [0.01, 0.3], got 5 |
a default that breaks its own declaration |
storage keys must have 1 to 128 characters |
an empty or too long key |
the storage holds at most 256 keys |
a 257th key |
the storage holds at most 262144 bytes; this value would bring it to 270000 |
the total is over 256 KiB |
`storage.get` is not available while the mod loads: call it from `setup` or an event handler |
storage.* at the top level of main.ts |
Pitfalls
- Start from the declared defaults. An element nobody configures receives no
elements.configureand would otherwise show nothing. - Build the nodes only during a play, and clear them at
game.songEnd, as the shipped HUD mods do. The skin editor still finds the element throughroot. - Option names are alphanumeric:
textColor, nevertext-color. Element names are the other way round:hits-row, neverhitsRow. - A color option set to hex does not follow the theme; the default
theme:textdoes. Defaults should be roles for text and surfaces. - Do not store anything the player must not lose in a variable: use
storage.set. And do not write on every frame: the file is written once per second at most, and your script pays for each call. - A
player: trueoption on a placeable element is edited in the skin editor anyway; the flag only adds a place in Settings for an element without one. - A
requireddependency makes your package disappear when the other is removed. Keep dependencies optional unless the package is useless without it. - Do not read another package's storage or call its functions: there is no such API. Use an element.
See also
- Build a HUD element for the nodes you draw from the options.
- Write a skin, which configures the elements of the HUD mods.
- storage.* and ctx reference and the event
elements.configure. - Mod package format for
fonts,imagesand the limits of a package. - Limits and Troubleshooting.