Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Playing a sound over and over again

Reaper Broda
Registered User
Join date: 14 Jul 2006
Posts: 4
09-17-2006 13:17
Hello! I'm new in scripting (very-very new :)), and I want to ask for a script that I embed into an object and if I say something it turns on the sound and it plays over and over again until I say stop or something.

So, here's what I want:

I have a sound that is 8.3 seconds in length. Now, when I say "Muzik", it is playing it, and when it gets to 8.3 then it plays again (and everyone can hear it!!!). And if I say "Stop Muzik" then it stops.

Can someone write a script for me like I said above? (Sry if I post it on a wrong forum!)
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
09-17-2006 15:31
CODE


string SOUND;
integer CONST_CHANNEL = 0; //Change this to the channel you wish to talk on


default
{
state_entry()
{
SOUND = llGetInventoryName(INVENTORY_SOUND, 0); //Gets the first sound in the object
llListen(CONST_CHANNEL, "", llGetOwner(), "");
}

listen(integer channel, string name, key id, string message)
{
if(llToLower(message) == "musik")
{
llLoopSound(SOUND); //Loops the sound for you until you tell it to stop
}
else if(llToLower(message) == "musik off")
{
llStopSound(); //Stops the sound
}
}

changed(integer change)
{
if(change & CHANGED_INVENTORY)
{
SOUND = llGetInventoryName(INVENTORY_SOUND, 0); //If you put in a sound or take it out. Not a very smart script.
}
}
}



there you are this should work, barring parsing errors :P just wrote it in the forums so didn't check it.
Reaper Broda
Registered User
Join date: 14 Jul 2006
Posts: 4
Huh???
09-18-2006 07:55
Maybe the script is wrong (I doubt it...), or I'm very new at scripting (this will be the problem), but I can't make it to work... :\

Please, explain me step-by-step how to make it work!
Like:

What should I change into what, do I need to do something with the sound...etc.

Please help me!
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
09-18-2006 13:14
From: Reaper Broda
Maybe the script is wrong (I doubt it...), or I'm very new at scripting (this will be the problem), but I can't make it to work... :\

Please, explain me step-by-step how to make it work!
Like:

What should I change into what, do I need to do something with the sound...etc.

Please help me!


You don't need to change anything, but if you want to change CONST_CHANNEL to the channel you wish to talk on. Then make a prim in world, put the sound you want to play inside the prim, then copy and this script and put it in that prim. Then say musik on the appropriate channel and it should start playing.
Reaper Broda
Registered User
Join date: 14 Jul 2006
Posts: 4
Error :\
09-18-2006 13:25
(16,32) : ERROR : Function call mismatches type or number of arguments

It keeps writing this for "SOUND"

What am I doing wrong?

If I change "SOUND" to something else it says that
Name not defined within scope

I know that maybe I sound annoying, but as I said earlier: I'm VERY-VERY new to scripting...
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
09-18-2006 13:30
oops... made an error :P

CODE


string SOUND;
integer CONST_CHANNEL = 0; //Change this to the channel you wish to talk on
float VOLUME = 1.0; //change this to the volume you want, 1 being max 0 being min.

default
{
state_entry()
{
SOUND = llGetInventoryName(INVENTORY_SOUND, 0); //Gets the first sound in the object
llListen(CONST_CHANNEL, "", llGetOwner(), "");
}

listen(integer channel, string name, key id, string message)
{
if(llToLower(message) == "musik")
{
llLoopSound(SOUND, VOLUME); //Loops the sound for you until you tell it to stop
}
else if(llToLower(message) == "musik off")
{
llStopSound(); //Stops the sound
}
}

changed(integer change)
{
if(change & CHANGED_INVENTORY)
{
SOUND = llGetInventoryName(INVENTORY_SOUND, 0); //If you put in a sound or take it out. Not a very smart script.
}
}
}


Also use the wiki to explain what the functions do, this will help you learn. http://rpgstats.com/wiki/index.php?title=Main_Page
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
09-19-2006 00:48
If you only want on off control Touch would be better.
Reaper Broda
Registered User
Join date: 14 Jul 2006
Posts: 4
Thanks!
09-19-2006 04:33
Thanks for the script! Now it works! ^^