From MiniScript Wiki
Revision as of 04:09, 29 March 2021 by JoeStrout (talk | contribs) (added example from CBC#8)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search plays a sound. Call this on a Sound object initialized either Sound.init, or loaded via file.loadSound.


Parameter Name Type Default Value Meaning
volume number 1 volume (0-1) of the sound
pan number 0 left (-1) to right (1) stereo pan of the sound
speed number 1 speed multiplier (1 == standard speed)

Usage Notes

The sound will automatically stop if .loop is false, but will repeat until explicitly stopped if .loop is true. Note that speed will change both the duration and pitch of the sound, due to changing the speed of the waveforms being played.


Here is a simple example of loading and playing a sound.

s = file.loadSound("/sys/sounds/bonus.wav")

The following example (taken from this video) shows how to adjust the stereo pan of a sound based on the X position of a mouse click.

snd = file.loadSound("/sys/sounds/bongo.wav")

while true  // repeat forever (press Control-C to exit)
    if mouse.button then
        // play a sound, panning left/right according to mouse X position
        pan = mouse.x / 480 - 1 1, pan
        // wait for the mouse button to be released
        while mouse.button; yield; end while
    end if
end while