Loading articleโฆ
Loading 4weirdโฆ
Loading articleโฆ
DocsGames
Docs ยท music ยท games
The in-game runtime is a single dependency-free script: include /games/html/fourweird-music.js, call window.FourWeirdMusic, and your game plays $music:1 songs and SFX through lazy WebAudio โ fail-open when audio is missing, silent when a payload is invalid.
The runtime
Reference the runtime by its absolute /games/html/ path โ never a relative copy โ and it guards itself idempotently on window.FourWeirdMusic. The AudioContext is created lazily on the first play call and resumed if suspended, so autoplay policies stay happy.
game.html โ music wiring
/games/html/Walkthrough
Wire once, then drive everything through the M handle: songs for loops, baked SFX kind names for one-liners, volumes and mute for the options screen. Invalid payloads fail silently to false โ your game never crashes on a bad note.
<script src="/games/html/fourweird-music.js"> with the absolute path, then grab window.FourWeirdMusic. Including it twice is safe โ the second load returns early.playSong with a song object, a $music:1 wrapper, or a seed URL (fetched fail-open). Stop it with stopSong (alias: stop).playSfx with a baked kind name (raygun, death, coin, jump, win, lose, click, alarmโฆ), an SFX object, or JSON text via playSfxJson.setVolumes({ master, music, sfx }) and honor the player's choice with setMuted(true) on the options screen.Seed format
Game soundtracks live on as small JSON seeds: *.song.json loops transcribed from each game's signature sound (menu, boss, death, coin) and *.sfx.json one-shot recipes. The embed runtime enforces its own tight budgets โ songs โค 8KB, sfx โค 1KB, 8 tracks and 512 notes max โ so every seed stays playable anywhere.