LSL sound loop script for ambient sound
Free LSL ambient sound script for Second Life: loop birds, waves, rain or a fire crackle from any object, set the volume and touch to turn it on and off.
Sound brings a place to life: waves on a beach, birds in a garden, a crackling fireplace. This sound loop script plays a sound on repeat from any object, with a volume setting and touch to switch it on or off.
// Ambient Sound Loop - free LSL script from WhatSL (https://whatsl.com/scripts/lsl-sound-loop-script)
// Free to use, change and put in your own creations, also ones you sell.
//
// Plays a sound on repeat: birds, waves, a fire, rain, a shop jingle.
// Put a sound in the object's Contents (or paste a sound UUID into SOUND_NAME). Touch to turn it on and off.
string SOUND_NAME = ""; // "" = the first sound in Contents; or a sound name or UUID
float SOUND_VOLUME = 0.6; // 0.0 to 1.0; keep ambient sounds soft
integer START_ON = TRUE;
integer OWNER_ONLY = FALSE; // TRUE = only the owner can turn it on and off
integer gOn = FALSE;
string soundToPlay()
{
if (SOUND_NAME != "") return SOUND_NAME;
return llGetInventoryName(INVENTORY_SOUND, 0);
}
setSound(integer on)
{
llStopSound();
gOn = FALSE;
if (!on) return;
string snd = soundToPlay();
if (snd == "")
{
llOwnerSay("Put a sound in my Contents, or set SOUND_NAME.");
return;
}
llLoopSound(snd, SOUND_VOLUME);
gOn = TRUE;
}
default
{
state_entry()
{
setSound(START_ON);
}
touch_start(integer total)
{
if (OWNER_ONLY && llDetectedKey(0) != llGetOwner()) return;
setSound(!gOn);
}
changed(integer change)
{
if (change & CHANGED_INVENTORY) setSound(gOn);
}
}
Libre para usar, cambiar e incluir en tus creaciones, también en las que vendes.
How to set it up
- Put a sound into the object's Contents (or copy a sound's UUID).
- Add the script and save. The sound starts playing.
- Touch the object to stop it and touch again to start it.
Settings
- SOUND_NAME: empty plays the first sound in the Contents. You can also type a sound name or paste a sound UUID.
- SOUND_VOLUME: 0.0 to 1.0. Ambient sounds sound best soft, around 0.3 to 0.6.
- START_ON: whether the sound plays as soon as the script starts.
- OWNER_ONLY: TRUE stops visitors from switching it off.
Tips
- Use sounds that are made to loop, without a gap or click at the end.
- Visitors hear the sound near the object. Place several quiet sources around a big area rather than one loud one.
- For music for a whole parcel, use the parcel's music stream instead of a sound loop.
Frequently asked questions
Why can't I hear anything?
Check that sound effects are turned up in your viewer's volume controls, that the object has a sound in its Contents, and that you are close enough to the object.
Can I play several sounds in a row?
This script loops one sound. Playing a list of sounds needs llPlaySound with a timer for each clip.
Does a sound loop cause lag?
Very little. The region tells viewers to loop the sound once; the viewer does the rest.