Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Combining Two Scripts into One?

Orlando Trebuchet
Registered User
Join date: 28 Jan 2007
Posts: 9
11-23-2007 07:09
I'm trying to combine a sound touch script and a loop script into one script that loops a sound when you click the prim. The problem is that I'm not combining them properly.. Please help and any tips on this matter would be greatly appreciated... The two scripts are as follows:



// Sound Prim Script - On Touch
//
// Randomly picks a sound in inventory,
// plays it when touched.
//
// Set this between 0.0 and 1.0
float LOUDNESS = 0.5;
//
////////////////////////////////////////////////
default
{

touch_start(integer num)
{
integer sounds = llGetInventoryNumber(INVENTORY_SOUND);

if ( sounds <= 0 ) return;

string soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(sounds)) );
if ( soundname != "" )
{
llPlaySound( soundname, LOUDNESS );
}
}

}



// Sound Prim Script - Loop
//
// Repeatly plays the sound in inventory if there is
// ONE and ONLY ONE sound. Silent otherwise.
//
// Set this between 0.0 and 1.0
float LOUDNESS = 0.5;
//
////////////////////////////////////////////////
Noisy()
{
if ( llGetInventoryNumber(INVENTORY_SOUND) == 1 )
{
string soundname = llGetInventoryName(INVENTORY_SOUND, 0);
if ( soundname != "" )
{
llLoopSound( soundname, LOUDNESS );
}
}
else
{
llStopSound();
}
}
////////////////////////////////////////////////
default
{

state_entry()
{
llStopSound();
Noisy();
}

changed(integer change)
{
if (change & CHANGED_INVENTORY)
{
llStopSound();
Noisy();
}
}

}
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
11-23-2007 07:39
In the first script, change the llPlaySound to llLoopSound.
Tharkis Olafson
I like cheese
Join date: 17 Nov 2004
Posts: 134
11-23-2007 07:50
I'm not in SL to test, but you could try the following. It compiles ok in the LSLEditor though.

CODE

// Sound Prim Script - On Touch
//
// Randomly picks a sound in inventory,
// plays it when touched.
//
// Set this between 0.0 and 1.0
float loudness = 0.5;
string soundname;
integer sounds;
//
////////////////////////////////////////////////
default
{

touch_start(integer num)
{
sounds = llGetInventoryNumber(INVENTORY_SOUND);

if ( sounds <= 0 ) return;

if ( soundname != "" )
{
soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(sounds)) );
llLoopSound( soundname, loudness );
}
else
{
llStopSound();
soundname = "";
}
}

}
Orlando Trebuchet
Registered User
Join date: 28 Jan 2007
Posts: 9
11-23-2007 17:33
The sound loops now on click but I want to turn it off as well, I tried the first suggestion of adding LoopSound and the sound definitely looped on touch. But it did not turn the sound off.
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
11-24-2007 16:32
Add a global variable to keep track of whether the loop is playing or not, and use that to decide what to do when touched. *You could also use a new state, but in this case that might be overkill*

integer PLAYING=0;


...

if (PLAYING == 0 ) {
PLAYING = 1 ;
llLoopSound ....
}
else {
PLAYING = 0;
llStopSound()...
}
Orlando Trebuchet
Registered User
Join date: 28 Jan 2007
Posts: 9
I've got something goofed up here?
12-16-2007 20:11
Please examine the script below and help me correct a problem. I can't quite get it?


// Sound Prim Script - On Touch
//
// Randomly picks a sound in inventory,
// plays it when touched.
//
// Set this between 0.0 and 1.0
float loudness = 0.5;
string soundname;
integer sounds;
integer PLAYING=0;
//
////////////////////////////////////////////////
default
{

touch_start(integer num)
{
sounds = llGetInventoryNumber(INVENTORY_SOUND);

if ( sounds <= 0 ) return;

if ( soundname != "" )
{
soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(sounds)) );

if (PLAYING == 0 )
{
PLAYING = 1;

llLoopSound( soundname, loudness );
}
else
{
PLAYING = 0;

llStopSound();

soundname = "";
}
}

}
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
12-17-2007 00:10
// Note: Sound does not have to be in prims inventory.
// Just use its UUID key. You can get it by right-clicking the
// sound in your inventory and picking "Copy UUID key"
// and then paste it into the appropriate place in your script.

integer playing = FALSE;
string sound = "Your Sound UUID here";
float volume = 1.0;

default
{
touch_start(integer count)
{
playing = !playing;

if (TRUE == playing)
{
llLoopSound(sound,volume);
} else {
llStopSound();
}
}
}
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
12-17-2007 10:34
You did not say what the problem is.

I don't see the point of soundname. Why do you have that if ( soundname != "";)? Once it has started playing, soundname will be "Name of the Sound" and never be "", therefore you cannot turn it off.

My logic would be...



if (PLAYING == 0 )
{
PLAYING = 1;
soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(sounds)) );
llLoopSound( soundname, loudness );
}
else
{
PLAYING = 0;
llStopSound();
}


When you touch it, it plays one sound at random. When you touch it again, it stops. Is that what you want? Or, do you want it to change to a different sound each time you touch it?
_____________________
So many monkeys, so little Shakespeare.