Tuesday, September 2, 2014

Loop Sound On/Off by Touch [Level II]

Here's my simple script to loop a sound on/off  by touch.

In this case touch causes the prim to alternately loop and stop the sound Atmopshere.

To set the volume of the sound, change the first line to any number between 0.0 (silent) and 1.0 (maximum loudness).

Repalce the number in quotation marks with the UUID of your own sound or the name of your sound (if you use the name, the sound must be in the prim with the script).

Script Follows. Just highlight and cut, paste it into a script in your prim, save, and you're good to go.

float volume = 1.0;
// This will determine how loud the sound will play (from 0 to 1)
integer on = TRUE;
// this is an integer (whole number) that switches between off (FALSE, or 0) and on (TRUE, or 1)
// We start with the integer set to TRUE (on)

            //If you want to script to do something whenever it starts, your code goes here
    touch_start(integer x)
        // When touch starts
        if (on == TRUE)
             // Loop Sound
            llLoopSound("00a31197-3c8a-2d76-1ea0-09372a592ad7", 1);
             on = FALSE;

    else if (on == FALSE)
             // Stop Sound
             on = TRUE;


// ====================

No comments:

Post a Comment