Saturday, September 29, 2007

Simple Scripting for Sound

Written 27 September, 2007

Simple Scripting for Sound

As a proud graduate of the College of Scripting, Music, and Science (I worked through all the exercises), I’m actually able to write simple scripts. Well, and maybe some moderately complicated ones…

My ex-friend Aldo Zond (one day, out of the blue and without explanation, he unfriended everyone he knew except, I think, his business contacts, which is why he’s an ex-friend) was kind enough, before he became unkind, to give me a script which would play any sound I dragged into a prim with the script in it.

I used that script a lot for a while, and it worked fine.

But now I can do it myself.

Sounds are actually pretty easy, unless you’re chain-loading them.

The commands I’ve used are:

llPreloadSound (“soundname”);

llPlaySound (“soundname”, 1,0);

llLoopSound (“soundname”, 0.5);

llStopSound (“soundname”);

I think I have the syntax right.

To play a sound, you need to just make a prim, drag your sound into it, and make a New Script. You just replace the line that reads something like llSay(0, “Touched”); with llPlaySound (“yoursoundname”, 1);

Then, whenever you touch the prim, it will play your sound at volume 1.

If you use llLoopSound instead of llPlaySound, it will play the sound in a loop.

The number after the sound name is the volume at which it will play. The bigger the number, the louder the sound. I’m not sure what number signifies the highest volume.

When I changed this number in Aldo’s script, absolutely nothing happened. I would restart the script, but the volume would be the same.

It turns out you have to stop the sound to reset the volume—although I learned that you can just copy the prim (providing, of course, that your sound is copyable) and the new prim will play at the volume set in the script.

Woo hoo! Now you can make your own sounds!

-----

Pele’s bird and cricket sounds are powered by a free full perm environment sounds script Ante Flan threw in when I bought his swell ocean waves back in November. It differentiates sounds into day and night and plays them accordingly (I believe it does so by reading the position of the default position of the Second Life sun in the sim in which it resides. It also makes some nice little fireflies—although I prefer the bigger ones made by the full perm foxfire script, which Leaf Shermer was nice enough to give me.

I’ll make sure the environmental sound and foxfire scripts are in the Pele Freebies, which can be found at the Dragon Skybar and the long stone walkway outside the Gardens at Pele. The sound script includes free bird calls.

You can replace the sounds in the environmental sounds script with your own, but you’ll need to be sure you type the names of the sounds exactly. Otherwise you’ll get an annoying script error whenever the script tries to find a sound that isn’t present.

You know, like those animation overriders that are forever complaining that they can’t find a particular pose. Any time you’re in a big group of people, chances are someone’s tinkered-with AO will be spamming the Chat.

-----

Here's  a simple script (I didn't write it) to loop any script you put in a prim with the script (one sound only!):

integer on = FALSE;
string soundname = "";

default
{
state_entry()
{
on = FALSE;
soundname = llGetInventoryName(INVENTORY_SOUND, 0);
// llOwnerSay(soundname);
}

touch_start(integer total_number)
{
if(llDetectedKey(0) != llGetOwner())
return;
if(soundname != "")
{
if(on)
llStopSound();
else
llLoopSound(soundname, 1);
on = !on;
}
}
}

2 comments:

Corgi said...

What's the SLurl for the Dragon Skybar, please? I went looking for it once out of curiosity and got nowhere (rather literally).

Cheyenne Palisades said...

Dragon Skybar

http://slurl.com/secondlife/Forsaken/28/141/550