Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

playing sounds in order

verinca Bliss
Registered User
Join date: 6 Jan 2005
Posts: 1
05-13-2005 04:48
ok im more or less brand new to lsl and im told this is the best place to ask about the scripts im trying to make so hear gos

more or less what im trying to do is play a bunch of sounds in order and im haveing a hard time makeing it so the code to do this 1 works 2 isint ugly

the basic idea of what iv been working on so far is
default
{
state_entry()
{
llSetSoundQueueing(integer queue)
}

touch_start(integer total_number)
{
llPlaySound(key sound, float volume)
llPlaySound(key sound, float volume)
}
}

now it says that i can only que 1 sound at a time so the only way i know to do this that might work woud involv an if then for every sound and timer to set off the if then statments in order and on time all in one big loop but thats not very nice is ther some beter way of doing this
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
05-13-2005 05:15
No, using llSetSoundQueueing is still probably your best bet. Another option is to preload your audio using llPreloadSound and then use llSleep between each playback. You can determine the ideal delay between clips, though unfortunately there's no way to do it automatically.

If you're having trouble with your code, post it, and I can take a look for you.
_____________________
Need scripting help? Visit the LSL Wiki!
Omega Point - Catherine Omega's Blog
Ace Cassidy
Resident Bohemian
Join date: 5 Apr 2004
Posts: 1,228
05-13-2005 05:33
If all of your sounds are of the same length, then this code should do the trick. If they are of variable length, put the lengths into a list like the sound names, and reference that for your timer.

Also note that this loops your sounds forever. If you want it touch triggered, or something else, I'll leave that up to you to figure out.

CODE


float SOUND_LENGTH = 10.0; // whatever length your sound files are

list gSounds = [ "sound1", "sound2", "sound3" ];
integer gSoundIx;

default
{
state_entry()
{
llSetSoundQueuing(TRUE);
gSoundIx = 0;
llPreloadSound(llList2String(gSounds, 0));
llSetTimerEvent(SOUND_LENGTH); // give the first sound time to get loaded to the client(s)
}

timer()
{
llPlaySound(llList2String(gSounds, gSoundIx));
if ( ++gSoundIx < llGetListLength(gSounds) )
{
llPreloadSound(llList2String(gSounds, gSoundIx));
}
else
{
gSoundIx = 0;
llPreloadSound(llList2String(gSounds, 0));
}
}
}


Hope this works...

- Ace
_____________________
"Free your mind, and your ass will follow" - George Clinton
RacerX Gullwing
Magic Rabbit
Join date: 18 Jun 2004
Posts: 371
06-13-2005 04:04
typos maybe something changed anyway this one compiles

CODE
float     SOUND_LENGTH = 10.0;  // whatever length your sound files are

list gSounds = [ "sound1", "sound2", "sound3" ];
integer gSoundIx;

default
{
state_entry()
{
integer queue =TRUE;
llSetSoundQueueing(queue);

gSoundIx = 0;
llPreloadSound(llList2String(gSounds, 0));
llSetTimerEvent(SOUND_LENGTH); // give the first sound time to get loaded to the client(s)
}

timer()
{
llPlaySound(llList2String(gSounds, gSoundIx),1);
if ( ++gSoundIx < llGetListLength(gSounds) )
{
llPreloadSound(llList2String(gSounds, gSoundIx));
}
else
{
gSoundIx = 0;
llPreloadSound(llList2String(gSounds, 0));
}
}
}
Thili Playfair
Registered User
Join date: 18 Aug 2004
Posts: 2,417
06-13-2005 06:32
No idea where i found this one , but its in my awesome mess of scripts, can drop any wav's named
whatever01.wav
whatever02.wav
whatever03.wav
ectec ,
lenght doesnt matter much since it will play one then start next

CODE
integer waves_to_preload = 999;	   //wave files to Preload ahead of the wav being played.
integer preload_load_time = 1; // seconds pause between each preloaded wave file attempt b4 play comnences
vector set_text_colour = <1,0,0>; // colour of floating text label
float set_text_alpha = 1; //no idea what this is LOL
// program variables
list invlist;
integer total_wave_files; //number of wave files
integer last_wave_file_number; //final wave sequence number (note: sequence starts at zero
//- so this is 1 less than total wave files)
integer i; //used by timer() player
integer c; //user by sound() bufferer
string preloading_wave_name; //the name of the wave file being preloaded
string playing_wave_name; //the name of the wave being played
integer play = FALSE; //toggle for music playing or stopped
sound()
{
total_wave_files = llGetInventoryNumber(INVENTORY_SOUND);
last_wave_file_number = total_wave_files - 1; // because wav files are numbered from zero
float length = total_wave_files*9.0;
//llSay(0, "preloading " + (string)tottrack + " wavs. Play length " + (string)llFloor(length) + "secs");
integer c = 0;
//do full preload of sound
llSetSoundQueueing(TRUE); //ONLY WORKS ON llPlaySound not llTriggerSound
integer x = waves_to_preload;
if ( total_wave_files < waves_to_preload ) { x = total_wave_files; }
llSay(0, "(" + llGetScriptName() + ") " + (string)(x * preload_load_time) + " sec buffering..");
for (c = 0 ; c <= (x - 1) ; c++) { //preload X wave files b4 we play
//since wavs are numbered from 0 we minus 1
preloading_wave_name = llGetInventoryName(INVENTORY_SOUND, c);
llSetText(llGetObjectName() +
"\n(preloading " + (string)((x - c)* preload_load_time) + " secs)"
//////debug lines
//+ "\n--debug--\n"
//+ "Preload wav: " + (string)c
//+ " name: " + preloading_wave_name
//+ "\nkey: " + (string)llGetInventoryKey(preloading_wave_name)
//////end debug line
, set_text_colour, set_text_alpha);
//Attempt to preload first x wave files to local machines cache!
llTriggerSound(preloading_wave_name, 0.0);
llPreloadSound(preloading_wave_name);
//llWhisper(0, (string)c + " of " + (string)tottrack);
//llWhisper(0,"Preloading wav: " + (string)c + (string)llGetInventoryKey(preloading_wave_name));
llSleep(preload_load_time);
}
i=0; c=0;
llSay(0, "Done! Playing.. (" + (string)llFloor(length) + " secs) Click to stop.");
llSetTimerEvent(8.8);
}

default
{
on_rez(integer start_param)
{
//set text above object to the name of the object
llSetText(llGetObjectName(), set_text_colour, set_text_alpha);
llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
}
touch_start(integer total_number)
{
if (!play) {
//llTargetOmega(<0,0,1>,PI,1.0) ;
sound();
} else {
//llTargetOmega(<0,0,1>,0,0);
llSetTimerEvent(0.0);
llStopSound();
llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
llSay(0, "Stopping..");
llSetText(llGetObjectName(), set_text_colour, set_text_alpha);
}

play = !play;
}

timer()
{
if( i > last_wave_file_number )
{
//llSay(0, "finished.");
play = FALSE;
llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
llSetText(llGetObjectName(), set_text_colour, set_text_alpha);
//llResetScript();
llSetTimerEvent(0);
}
else
{
playing_wave_name = llGetInventoryName(INVENTORY_SOUND, i);
//llWhisper(0, "llPlaySound wav: " + (string)i + " " + (string)llGetInventoryKey(playing_wave_name) );
llPlaySound(playing_wave_name, 0.7);
llSetText( llGetObjectName() +
"\n(playing " + (string)i +" of "+ (string)last_wave_file_number +")"
, set_text_colour, set_text_alpha);

if(i + waves_to_preload <= last_wave_file_number)
{
preloading_wave_name = llGetInventoryName(INVENTORY_SOUND, i + waves_to_preload);
//llSetText( llGetObjectName() +
// "\n(playing " + (string)i +" of "+ (string)last_wave_file_number +")"
//////debug line
//+ "\n--debug--\n"
//+ "Playing key: " + (string)llGetInventoryKey(playing_wave_name) + "\n"
//+ "Preloading sequence: " + (string)(i + waves_to_preload)
//+ " name: " + preloading_wave_name
//+ "\nPreloading key: " + (string)llGetInventoryKey(preloading_wave_name)
//////end debig line
// , set_text_colour, set_text_alpha);

//llWhisper(0, "Preloading wav:" + (string)(i + waves_to_preload) + " " +
// (string)llGetInventoryKey(preloading_wave_name) +" last = " + (string)last_wave_file_number);
llTriggerSound(llGetInventoryName(INVENTORY_SOUND, i + waves_to_preload), 0.0);
llPreloadSound(llGetInventoryName(INVENTORY_SOUND, i + waves_to_preload));
}
}
i++; //increment for next wave file in sequence!
}
}


errf er well i could just give you one ingame