Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Touch on off script

Dnali Anabuki
Still Crazy
Join date: 17 Oct 2006
Posts: 1,633
06-27-2007 17:38
I have a script that I found that when you touch it the sound goes on and I managed to add something to make it play a loop when touched.

How do I add a touch event to get it to stop playing the sound?

I am very, very new to this and never programed so I'm sorry in advanced if this is one of those very easy things to do that I'm just not getting.

Here is the script so far. The sound is not stopping when it is touched but the script still compiles.



float LOUDNESS = 0.3; //Set this between 0.0 and 1.0

default
{
touch_start(integer number_detected)
{
integer sounds = llGetInventoryNumber(INVENTORY_SOUND);

if ( sounds <= 0 ) return;

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

state off
{
touch_start(integer number_detected)
{
llStopSound();
}

}
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
06-27-2007 17:40
Right after your loopsound statementm say:

state off;


And in your off state, right after your stop sound, say:

state default;

I think that would do it.
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
06-27-2007 17:45
[edit: RJ said it better, quicker, while Qie was still typing drivel.]

Also, if you have llLoopSound, you don't need the llPlaySound.

And if you want to get tricky, you could select the next random sound while the current one is looping, and llPreloadSound to make it start promptly next time 'round.
Dnali Anabuki
Still Crazy
Join date: 17 Oct 2006
Posts: 1,633
06-27-2007 18:42
Thanks Qie and RJ!

Whee! My first script...sort of..well, anyway, where I have a clue what's going on instead of just changing variables.

Thanks again!
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
06-27-2007 19:07
congratulations, Dnali. keep scripting...
Dnali Anabuki
Still Crazy
Join date: 17 Oct 2006
Posts: 1,633
06-27-2007 19:36
Thank you..my lovely bells are working great.

Here is what I came up with from your advice:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

float LOUDNESS = 0.3; //Set this between 0.0 and 1.0

default
{
touch_start(integer number_detected)
{
integer sounds = llGetInventoryNumber(INVENTORY_SOUND);

if ( sounds <= 0 ) return;

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

}
}// End of default

state off
{
touch_start(integer number_detected)
{
llStopSound();
{
state default;
}

}
}