to begin with, mainly beeps, whooshes, and bangs!
It is important to be able to make some noise sometimes! LSL provides a bunch of commands for this. But first you need to have a sound to play. Check your Inventory to see if you have some. If not, you might be able to find someone in the Second World to give you one. Get them from me or Tiplife! (But you can also upload one or your own by selecting "Upload SoundFile" from the File menu, for L$10. It must be a wav file, less than 10 seconds long, sampled at 44100 Hertz. We will see some ways to get around these limits later, but this is enough for beeps, whooshes, bangs, and even little bits of music. You can check your sounds and change their sampling rate with a free sound editor like audacity if you need to.)
If you have a noise called "ping" then you can make an object play this sound when it is touched. The sound I used is this one. First, click on the object, click on Edit, and click to open Contents. Now drag "ping" from your inventory to the Contents window. Then click on New Script and modify it like this:
default { state_entry() { llSay(0, "Hello, Avatar!"); } touch_start(integer total_number) { llTriggerSound("ping",1.0); } } The new command is in line 10. It takes two parameters, as you can see: the first is the name of the sound, and the 1.0 says to play the sound at full volume. Putting 0.5 here would play the sound at half volume. (Also if you click Preferences, you can select Audio&Video to adjust the volume in various ways.)
Sometimes you want a noise that will not stop, noise that will last as long as the object that makes it. One command that does this is llLoopSound. Try it out!
In case you meet someone you like, it is nice to have some little presents. Virtual chocolates are not quite the same as real ones because they are hard to taste, but virtual flowers are nice (we'll work on those later), and the music can be real! And if you meet someone else (especially someone boring or dangerous looking!) it is good to have another sound to play.
Let's create an object for a script that will play a nice sound if it gets touched by someone you like and otherwise will make a different noise! Here are the sounds I used: dance.wav, funeral.wav (but hopefully you can find better ones!). We can choose which one to play with the if-(test)-then-else pattern that we introduced earlier:
default { state_entry() { llSay(0, "Hello, Avatar!"); llSleep(1.0); llOwnerSay("I do what the script says!"); } touch_start(integer detected) { if (llDetectedName(0)=="Tiplife Eggplant") { llLoopSound("dance",1.0);} else { llLoopSound("funeral",1.0);} } } After you put this script in an object, make sure to also drag the dance and funeral sound files into its contents, then you are ready to try it!
Notice I put an llSleep command in the state_entry block, so that the object will pause for 1.0 seconds after saying hello, just because it's sometimes rude to talk and talk without pausing!
You can fit more in 10 seconds than you might think! Try one of these: dancing, cm1, cm2, cool, postal, bluemoon, foo, jcm, shesaid.
I tried to cut some of these so that they would not be too bad in a loop. Try writing a script that plays cm1 once, and then loops cm2. (And when you can do that, I'm sure you'll have some better ideas too!)
Let's build one more simple sound script, using this good boom sound. This script will be different because the script will keep a number and count each time it is touched.
integer counter = 1; default { state_entry() { llSay(0, "Hello, Avatar!"); llSleep(1.0); llOwnerSay("I do what the script says!"); } touch_start(integer detected) { if (counter < 3) { llSay(0,"Now I have been touched "+(string)counter+" times"); llSay(0,"You will be sorry when I get touched 3 times!"); counter = counter + 1; } else { llTriggerSound("boom",1.0); llDie(); } } } There are a couple of new things in this script! Line 1 announces that the script is going to keep a number, an integer that we will call counter -- we could have named this integer anything we wanted. Notice that we use just one equal sign here, because we mean "make equal to".
Line 15 prints out how many times the object has been touched. To do this, it puts the string "Now I have been touched " together with the string form of the number counter, and then adds the string "times." (We will talk more about this later!)
Line 17 adds 1 to the counter. Notice this time we use just one equal sign, since we mean "make equal to" again.
Line 21 makes a boom noise, and line 22 tells the object to self-destruct! Try it out, with however much you want to count, and whatever you want to say.