On this page

← All documentation

Gameplay modifiers, scroll speeds and key actions

Declare switches for the Mods tab, scroll speed systems and key actions of a mod, with every closed list and limit Rust applies.

Three registrations let a mod add to the game's own screens without building any interface of its own: a gameplay modifier (a switch on the Mods tab of the selected chart), a scroll speed system (a way to choose how fast the notes travel) and a key action (a key the player can rebind in Settings → Controls). All three are declared in setup, and Rust validates every declaration when it is made.

A complete example

The example mod declares one of each. It is type-checked, and the repository's tests load it through the real engine.

/// <reference path="../../../mods/sdk/modding.d.ts" />

// What a mod can declare for the Mods tab and the Controls page, in one file: a modifier whose script sets the playfield's cover (the
// game draws it), a scroll speed system, and a key action the player can rebind. Every declaration is made in `setup`, never
// later, and every one is checked by Rust when it is registered: a refused call throws, and the mod fails with the reason.
export default defineMod({
  id: "example.modifiers",
  name: "Example modifiers",
  version: "1.0.0",
  apiVersion: 2,
  author: "PVNG",
  description: "A cover modifier, a scroll speed in screens per second and a key that shows a hint.",
  setup() {
    // `kind: "noteMask"` is a modifier whose script sets how the playfield is drawn: when a play starts, the game delivers
    // `playfield.noteMask` with the player's value of every slider declared in `params` (clamped to its bounds), and the handler answers
    // with `playfield.setNoteMask`. Here a cover on the spawn side, as tall as the slider says, with a soft edge. The numbers are in
    // percent of the box height and Rust validates them; nothing runs while the play is drawn. `group` and `icon` come from closed lists;
    // leave them out for the kind's own.
    gameplay.register({
      id: "curtain",
      name: "Curtain",
      description: "A cover hides the notes until they are close. Drawn only: judging and the ranking are unchanged.",
      kind: "noteMask",
      group: "layout",
      icon: "fold-vertical",
      // Keys of other modifiers (`<modId>/<id>`): the Mods tab switches them off when this one is switched on.
      conflictsWith: ["pvng.hidden/hidden"],
      params: [
        { id: "height", label: "Curtain height", description: "How much of the box the curtain covers, in percent of the box height.", section: "curtain", min: 10, max: 100, step: 5, default: 50, unit: "%" },
      ],
    });
    ctx.on("playfield.noteMask", (request) => {
      if (request.id !== "curtain") return;
      playfield.setNoteMask({ sudden: { size: request.params.height, feather: 10 } });
    });

    // A scroll speed system: the player picks a number, `toMs` says how many milliseconds a note takes to travel from where it appears
    // to the receptors. `travel` is the distance in screen heights (0.8 in the native playfield), so the value here is a velocity.
    scrollSpeed.register({
      id: "screens",
      name: "Screens per second",
      param: { label: "Screens/s", short: "S", min: 0.2, max: 3, step: 0.05, default: 1.1 },
      toMs: (value, { travel }) => (travel / value) * 1000,
    });

    // A key action: listed under the mod's name in the Controls page, with `KeyH` as its default key.
    controls.register({ id: "toggle-hint", name: "Show the hint", defaultKey: "KeyH" });
    let shown = false;
    // The hint is drawn for the length of a play only: a mod's layer must be cleared at song end.
    ctx.on("game.songStart", () => {
      hud.text({
        id: "hint",
        text: "Hint: the curtain hides the notes until they are close",
        visible: false,
        layout: { x: 0.5, y: 0.08, anchor: "center" },
        style: { color: "#ffffff", size: 0.025 },
      });
      shown = false;
    });
    ctx.on("game.songEnd", () => hud.clear());
    ctx.on("controls.action", (action) => {
      if (action.id !== "toggle-hint" || !action.pressed) return;
      shown = !shown;
      hud.update({ id: "hint", visible: shown });
    });
  },
});

Every registered key is <modId>/<id>: here example.modifiers/curtain, example.modifiers/screens and example.modifiers/toggle-hint.

Rules that apply to all three

  • Only a mod can register them, and only in setup. A call from an event handler, a skin or a map script is refused.
  • An id is 1 to 32 characters among a-z, 0-9 and -. A name or a description is non-empty, has no control character and fits its limit (below).
  • A refused call throws in the script with the reason. If setup does not catch it, the mod fails and its other declarations are withdrawn.
  • A disabled, failed or uninstalled mod loses its declarations at once. A choice the player made for a key that no mod provides any more does nothing.

Typical refusals:

modifier id must be 1 to 32 characters among a-z, 0-9 and `-`, got "Bad Id"
gameplay.register is only available in a mod's setup
a mod registers at most 8 gameplay modifiers

Gameplay modifiers

gameplay.register({
  id: "steady",
  name: "Steady",
  description: "The pause key and a lost window focus do nothing during the play.",
  kind: "noPause",
});
Field Rule
id 1 to 32 characters, a-z0-9-, unique in the mod
name 1 to 32 characters
description 1 to 200 characters, shown when the player hovers the switch
kind one of the kinds below
group optional, one of assist, layout, longNotes, timing, difficulty, other; the kind's own group when absent
icon optional, one of the 28 icons below; the kind's own icon when absent
conflictsWith optional, at most 8 keys <modId>/<id>; never the modifier's own key

A mod registers at most 8 modifiers. The key must be unique among all mods.

The kinds

The kind is what the game does when the player switches the modifier on. A script cannot add behaviour to a native kind and cannot add parameters to it: the game declares them for the kind. Two kinds have a script behind them: chartTransform (it rewrites the notes) and noteMask (it sets how the playfield is drawn, and declares its own parameters).

Kind What it does Default group, icon Parameters
auto The game plays the chart perfectly by itself: no score, no replay. assist, bot none
ghost The best play of the map (or the one picked in the leaderboard) is replayed beside the player's own, and the HUD can compare its accuracy with the player's live. Scored and recorded as usual. assist, ghost none
fullLn A tap with room before the next note of its column becomes a hold. It needs the timing points and the real-time constants of the rate, which a script is not given. The play is unranked as soon as a setting differs from its default: the ranked version, with fixed settings, is built into Prism. longNotes, unfold-vertical several: gap, minimum and maximum length, which columns and chords convert, end snapping…
chartTransform Your script rewrites the notes at the start of a play: see Transforming a chart. A play whose notes changed is unranked. other, sliders-horizontal none
noteMask Your script sets covers and a lift for the playfield at the start of a play: see Drawing the playfield. Drawn only: the chart and the judging are untouched, the play stays ranked. layout, eye declared by your script, in params
noPause The pause key and the window losing the focus do nothing during a play. Quit, restart and Skip intro still work. No note changes, so the play stays ranked and carries no badge. It applies to a normal play only: a watched replay, a training and the visualizer pause as usual. other, shield none

mirror, noLn, rankedFullLn and noMines are in the SDK type but a mod cannot declare them: Mirror, No long notes, the ranked Full long notes (fixed settings, no parameter) and No mines (the chart's mines are left out) are built into Prism, keys prism/mirror, prism/no-ln, prism/full-ln and prism/no-mines, and are always published first, in that order. Their plays stay ranked. Declaring one fails with:

Mirror is built into Prism: a mod cannot declare it
No long notes is built into Prism: a mod cannot declare it
Full long notes is built into Prism: a mod cannot declare it

The shipped mods are good models: pvng.auto, pvng.ghost, pvng.full-ln and pvng.no-pause contain nothing but this declaration, pvng.random is the shipped chartTransform mod, and pvng.hidden, pvng.sudden and pvng.lift are the shipped noteMask mods. The kinds hidden, sudden and lift of earlier versions are gone: those three modifiers are noteMask mods now, with the same keys, parameters and look.

Drawing the playfield: noteMask

A modifier of kind noteMask changes how the playfield is drawn: a cover over the region the notes travel through, or a lift of the receptor line. When a play is prepared, the game delivers the event playfield.noteMask to your script with the values the player chose for your sliders, and your script answers with playfield.setNoteMask(…). Rust checks every number and the renderer draws the result. Nothing of your script runs while the play is drawn, and your script cannot press a key or change a judgement: a mask only draws, so the play stays ranked.

This is the shipped Lift, complete:

/// <reference path="../sdk/modding.d.ts" />

// Lift is a script mod: the receptor line and the judgement line are raised toward the spawn side, so the notes travel a
// shorter distance and the space behind the receptors grows. When a play is prepared the game delivers `playfield.noteMask`
// with the player's value of the slider declared below, and this script answers with `playfield.setNoteMask`: a lift, in percent
// of the box height. Rust validates the number (the lines never pass the spawn edge) and the renderer draws it; no script runs
// while the play is drawn. Judging stays on the song's time and the ranking is unchanged, and the replay records the number,
// so a watched replay looks the same without this mod.
export default defineMod({
  id: "pvng.lift",
  name: "Lift",
  version: "2.0.0",
  apiVersion: 2,
  loadOrder: 394,
  author: "PVNG",
  description: "A Mods tab switch that raises the receptor line toward the spawn side.",
  setup() {
    gameplay.register({
      id: "lift",
      name: "Lift",
      description: "The receptor and judgement lines are raised. Drawn only: judging and the ranking are unchanged.",
      kind: "noteMask",
      group: "layout",
      icon: "move-vertical",
      params: [
        { id: "liftHeight", label: "Lift height", description: "How far the receptor line is raised, in percent of the box height.", section: "lift", min: 0, max: 50, step: 1, default: 20, unit: "%" },
      ],
    });
    ctx.on("playfield.noteMask", (request) => {
      if (request.id !== "lift") return;
      playfield.setNoteMask({ lift: request.params.liftHeight });
    });
  },
});

Three things to see in it:

  • params declares the sliders of the modifier. They appear on the Mods tab, and the player's values are kept in the setting gameplayModParams under the modifier's key. A modifier declares at most 8, and only a noteMask modifier may declare any.
  • The event carries { id, params }: the id of the modifier the player switched on (one handler serves every modifier of the mod, so test it) and the value of each slider by id. The game already clamped the player's saved value to your min and max, or used your default; an id you did not declare never arrives.
  • playfield.setNoteMask only works inside that handler. A handler that never calls it changes nothing.

A declared slider is checked like everything else:

Field Rule
id 1 to 32 letters and digits, the first a letter, unique in the modifier; the key of the saved value (the interface translates chartparam.<id>.label and .description when it has them, else it shows your English texts)
label 1 to 32 characters
description 1 to 200 characters
section 1 to 32 characters, a-z0-9-; the sliders of one section are listed together
min, max, step, default integers, -1000000 <= min < max <= 1000000, 1 <= step <= max - min, min <= default <= max
unit optional, % or ms

What a mask can say. Every size is a percent of the height of the lanes' box, an absent part is drawn as the skin draws it, and a number is rounded to the nearest whole percent:

Part Values What is drawn
sudden: { size, feather } size 10 to 100, feather 0 to 50 A cover on the spawn side: the notes appear from behind it. It never reaches the receptors and replaces the skin's lane cover. The last feather percent of its far edge fades out.
hidden: { size, feather } same The same cover hung from the receptors of each lane toward the spawn side: the notes fade out as they approach.
lift 0 to 50 (0: not raised) The receptor line and the judgement line are raised toward the spawn side, never past the spawn edge: the notes travel a shorter distance. Judging stays on the song's time.

The colour and the opacity of a cover come from the skin (laneCoverColor, laneCoverOpacity); an opacity of 0 turns it off.

What Rust does with a mask:

  • A number must be finite and inside its range. An out-of-range number, NaN, an infinity, an unknown field or a wrong type throws in your script with the reason. The first refusal drops the whole modification of your mod, even if your script catches the exception and calls again: the play is drawn without it and the player sees a notice. With several valid calls in one handler, the last one wins.
  • A handler that is missing, throws, runs out of its execution budget or out of memory is dropped the same way. The other modifiers and the play are untouched.
  • Two mods of one play cannot set the same part (sudden, hidden, lift): the one that loads later is dropped with a notice. A mod that sets another part is not in conflict.
  • The result is copied once, when the play starts, into what the renderer draws and what the replay records (chartMods.visual). A mask is therefore the same for the whole play; it is not a function of time. A replay is drawn the same without your mod installed.

Typical refusals:

playfield.setNoteMask refused the mask: sudden.size 101 is outside 10..100
playfield.setNoteMask refused the mask: lift is not a finite number
Curtain: sets `sudden`, which a mod before it already set; the play goes without it
only a `noteMask` modifier declares `params`: the game declares the parameters of the other kinds

Groups and icons

group is where the Mods tab lists the modifier. icon is the name of a Lucide icon from a closed list, because the interface draws these and nothing else:

bot, ghost, flip-horizontal-2, shuffle, minus, unfold-vertical, fold-vertical, chevrons-down-up,
align-vertical-space-between, ruler, gauge, timer, zap, dices, repeat, eye, sliders-horizontal,
swords, feather, flame, shield, skull, audio-lines, rows-3, move-vertical, equal,
arrow-down-to-line, between-horizontal-start

A name outside the list is refused: modifier icon "star" is not an allowed icon. A group outside the list gives modifier group "x" is not one of assist, layout, longNotes, timing, difficulty, other.

Conflicts

conflictsWith lists keys of modifiers that cannot be combined with this one. The Mods tab switches the others off when the player switches this one on. If a selection holds both anyway, the game applies its own rule. Each entry must look like <modId>/<id>; the other modifier does not have to exist. The built-in prism/no-ln and prism/full-ln name each other and pvng.full-ln/full-ln, and the reverse.

What the game publishes

The gameplayMods data the interface reads has, for each modifier: key, modId, name, description, kind, group, icon, conflictsWith and params. The player's choice is the setting gameplayMods (the chosen keys); the values of the parameters are the setting gameplayModParams, checked (bounds, step, choices) when a play starts.

Scroll speed systems

A system is a named parameter, such as osu!mania's scroll speed or Etterna's C-mod, and the function that turns each of its values into the game's own scroll time: the milliseconds a note takes to go from where it appears to the receptors. The game plays with that time only.

scrollSpeed.register({
  id: "c-mod",
  name: "Etterna",
  param: { label: "C-mod", short: "C", min: 120, max: 1800, step: 5, default: 200 },
  toMs: (cmod, { travel }) => ((travel * 480) / ((64 * cmod) / 60)) * 1000,
});
Field Rule
id 1 to 32 characters, a-z0-9-, unique in the mod
name 1 to 64 characters
param.label 1 to 32 characters
param.short optional, 1 to 8 characters written before the value (C gives C700); without it the game writes the label, a space and the value
param.min, max, step, default finite, min < max, 0 < step <= max - min, min <= default <= max
toMs(value, context) a function; returns the scroll time in milliseconds
  • A mod registers at most 8 systems.
  • The suggested slider grid is min to max by step, and it has at most 4096 values.
  • context.travel is the distance a note covers during the scroll time, in screen heights: 0.8 in the native playfield. Everything else (pixels, the position of the receptors, the chart) cancels out, so a conversion only needs this number.
  • After the mods load, the game calls toMs for every value of the grid. A value whose call throws, or returns something other than a positive finite number, is left out of the grid. If no value converts, the system is dropped and the mod's log says why.
  • A value the player types by hand is converted on demand by the same function; it is not clamped to the grid.

Key actions

controls.register adds an action to Settings → Controls, listed under the name of your mod, with a default key. The controls.action event then tells the mod when the key goes down or up during a play.

Field Rule
id 1 to 32 characters, a-z0-9-, unique in the mod
name 1 to 64 characters, shown in Controls
defaultKey a physical key code accepted by the game (KeyA, Space, F5…): the inventory in crates/core/src/mode/key-codes.json
  • A mod registers at most 32 actions.
  • The event carries { id, pressed, timeUs }. It is delivered only to the mod that declared the action, with the song time in microseconds.
  • Events travel through a bounded queue to the mods thread. A full queue can lose events: do not use this to hold a scoring state or anything critical.
  • The player's binding persists even if the mod is disabled, and only the actions of active mods are offered. A change takes effect at the next play. Game inputs and replays are never replaced by a mod action.
action defaultKey must be an accepted physical key code, got "Hyper"
action id is registered twice
a mod registers at most 32 actions

Pitfalls

  • Choosing kind is not a way to run your own code in the game. For anything that is neither chartTransform nor noteMask, the declaration is all there is: look at content/mods/no-pause/main.ts.
  • A noteMask handler runs once per play, before it starts: it cannot follow the song, the beat or the player. Compute the numbers from request.params and answer.
  • Do not register in ctx.on(...) handlers: the registries are closed once the mods have loaded.
  • A group or an icon that looks right but is not in the list fails the whole setup: copy the names from this page.
  • A toMs that depends on anything but its two arguments (a global, the time) gives a grid that no longer matches what the game plays.

Reference

Source in the game repository: crates/modding/src/modifiers.rs,crates/modding/src/note_mask.rs,crates/modding/src/scroll_speed.rs,crates/modding/src/controls.rs,crates/modding/src/api.rs,crates/core/src/visual_mods.rs,crates/core/src/mode/key-codes.json,content/examples/mods/modifier-set/main.ts,content/mods/lift/main.ts,content/mods/no-pause/main.ts,content/mods/scroll-etterna/main.ts