-
Notifications
You must be signed in to change notification settings - Fork 0
Sound
The Sound module (RGXSound) provides sound registration, variant playback, mute/unmute, persistence, and welcome sounds.
Register a sound and get a handle object for playback and control.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
id |
string | Yes | — | Unique sound identifier |
opts.path |
string | Yes | — | Sound file path. Use %d for variant placeholder. |
opts.name |
string | No | id | Display name |
opts.variants |
number | No | 0 | Number of variants (0 = single sound) |
opts.defaultVariant |
number | No | 1 | Default variant number |
opts.volume |
number | No | 1.0 | Playback volume (0-1) |
opts.muted |
bool | No | false | Initial mute state |
opts.welcome |
bool | No | false | Play on login |
opts.setting |
string | No | nil | Setting key for SavedVariables |
opts.welcomeSound |
string | No | nil | Alternate welcome sound path |
When variants > 0, the path should contain %d as a placeholder for the variant number:
local kill = Sound:Register("kill", {
path = "Interface\\AddOns\\MyAddon\\Sounds\\kill_%d.ogg",
variants = 5,
name = "Kill Sound",
})This creates paths: kill_1.ogg, kill_2.ogg, kill_3.ogg, kill_4.ogg, kill_5.ogg.
Play the sound.
- If
variantis a number: play that specific variant - If
variantis"default": play the current default variant - If
variantis"random"or nil: play a random variant (if variants > 0) - If no variants: play the single sound file
handle:Play() -- random variant
handle:Play(3) -- variant 3
handle:Play("default") -- current default variantInitialize the sound handle. Validates the file path and applies defaults. Called automatically during registration.
Mute or unmute the default variant:
handle:MuteDefault()
handle:UnmuteDefault()Play the sound at full volume regardless of mute/enable state. Useful for configuration UIs.
Get the current variant number:
local v = handle:GetVariant() -- → 3Set the current variant. 1-indexed. Clamped to [1, variants]:
handle:SetVariant(2)Get the current setting key (for SavedVariables persistence).
Set the setting key. When set, the handle reads/writes its state from _G.RGXFrameworkDB.sound[key].
Enable or disable the sound. Disabled sounds do not play on :Play():
handle:Disable()
handle:Enable()Play the welcome sound if welcome = true was set during registration. Called automatically by the framework on PLAYER_LOGIN.
Save current state for next login. Called automatically by the framework on PLAYER_LOGOUT.
local Sound = RGX:GetSound()
-- Register a kill sound with 5 variants
local killSound = Sound:Register("myAddon_kill", {
path = "Interface\\AddOns\\MyAddon\\Sounds\\kill_%d.ogg",
variants = 5,
name = "Kill Sound",
volume = 0.8,
muted = false,
setting = "killSound",
})
-- Register a single UI sound
local uiSound = Sound:Register("myAddon_click", {
path = "Interface\\AddOns\\MyAddon\\Sounds\\click.ogg",
name = "UI Click",
volume = 1.0,
})
-- Register a welcome sound
local welcomeSound = Sound:Register("myAddon_welcome", {
path = "Interface\\AddOns\\MyAddon\\Sounds\\welcome.ogg",
name = "Welcome",
welcome = true,
volume = 0.5,
})
-- In combat handler
killSound:Play() -- random variant
-- In config UI
uiSound:Test() -- always plays, ignores muteWhen setting is provided during registration:
- On init: reads
_G.RGXFrameworkDB.sound[setting]for saved state - On play/update: writes current state back to the same key
- On logout:
handle:Logout()ensures state is saved
Persisted data includes: variant, muted, enabled, volume.