Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with a sound loop script

Patti Frye
Registered User
Join date: 25 Aug 2006
Posts: 60
08-28-2007 16:26
Hey everyone.
Could someone help me turn the sound loop script into a listen script that I could turn off and on using the chat command "/1 on" and "/1 off" ??

It probably needs some cleaning up as well. I really don't need the group intergers in it.

As it is right now it is a "touch" on/off script.

I know it's super easy for all you knowledgeable scripters out there, but for me...I'm still learning.

(Start Code)

integer group = FALSE;
integer anyone = FALSE;
integer on = FALSE;
string sound_name;
float volume;

integer allowed( key lid )
{
if ( lid == llGetOwner() ) {return TRUE;}
if ( group )
{
if ( llSameGroup( lid ) ) {return TRUE;}
}
if ( anyone ) {return TRUE;}
return FALSE;
}

init()
{
group = FALSE;
anyone = FALSE;
if ( llGetInventoryType( "allow_group" ) == INVENTORY_NOTECARD )
{
group = TRUE;
}
if ( llGetInventoryType( "allow_anyone" ) == INVENTORY_NOTECARD )
{
anyone = TRUE;
}
llStopSound();
on = FALSE;
}
default
{
state_entry()
{
init();
}
on_rez( integer r )
{
init();
}
changed( integer c )
{
if ( c & CHANGED_OWNER )
{
llResetScript();
}
}
touch_start( integer t )
{
if ( allowed( llDetectedKey(0) ))
{
if ( on )
{
on = FALSE;
llStopSound();
}
else
{
on = TRUE;
sound_name = llGetInventoryName( INVENTORY_SOUND ,0 );
volume = 1.0;
llLoopSound( sound_name,volume );
}
}
}
}

(End Code)

Thanks in advanced.
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
08-28-2007 19:59
Patti...

...you'll want to take the touch_start() event out of the script and replace it with:

listen(integer channel, string name, key id, string message)
{
if(message == "on";) // start sounds
else if(message == "off";) //stop sounds
}

You'll also want to "create" a listen in the state_entry() or on_rez() event:

llListenRemove(handle);
handle = llListen(1,"",NULL_KEY,"";);

That listen will pick up anyone saying /1 on or /1 off.
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Darko Lednev
Registered User
Join date: 20 Aug 2007
Posts: 31
08-28-2007 20:18
Here it is. I left the touch part in.

integer listenChan = 1; // Change to desired channel for chat commands
float soundVolume = 1.0; // Volume of the sound (0.0 - 1.0)

integer on = FALSE;
string soundName;

default
{
state_entry()
{
soundName = llGetInventoryName( INVENTORY_SOUND ,0 );
llListen(listenChan, "", NULL_KEY, "";);
}

touch_start( integer t )
{
if ( on )
{
on = FALSE;
llStopSound();
}
else
{
on = TRUE;
llLoopSound( soundName, soundVolume );
}
}

listen(integer channel, string name, key id, string message)
{
if (message = "on";)
{
on = TRUE;
llLoopSound(soundName, soundVolume);
}
else if (message = "off";)
{
on = FALSE;
llStopSound();
}
}
}
Patti Frye
Registered User
Join date: 25 Aug 2006
Posts: 60
08-28-2007 21:56
Hey thanks Darko. Works great...except for one little thing.
The sound comes on just fine when I chat /1 on.
But it doesn't turn off when I chat /1 off.

I have to touch the prim to shut off the sound...anyway of fixing this little item?
Darko Lednev
Registered User
Join date: 20 Aug 2007
Posts: 31
08-28-2007 22:40
Uuupppssss :)
A little typo...forgot to put two "=" signs in the "if" statements. :(

Find the line:
From: someone
if (message = "on";)

and replace it with:
From: someone
if (message == "on";)

...also find:
From: someone
else if (message = "off";)

and replace it with:
From: someone
else if (message == "off";)
Patti Frye
Registered User
Join date: 25 Aug 2006
Posts: 60
08-28-2007 23:43
Oh Perfect...Thank you so much Darko