Satai Diaz
Humble Bounty Hunter
Join date: 9 Aug 2003
Posts: 133
|
07-08-2005 21:58
I currently only have this script for playing a 9 second sound file when an object is clicked. What I want to do is be able to put 3 or 4 different sounds inside of an object and whenever that object is clicked to play only one of the sounds and in a random fashion. list invlist; integer tottrack; integer i;
integer play = FALSE;
sound() { llSetTimerEvent(9.0); tottrack = llGetInventoryNumber(INVENTORY_SOUND); float length = tottrack*9.0; llSay(0, (string)length); llPreloadSound(llGetInventoryName(INVENTORY_SOUND, 0)); i=0; }
default { touch_start(integer total_number) { if (play) { sound(); } else { llSetTimerEvent(0.0); } play = !play; } timer() { llTriggerSound(llGetInventoryName(INVENTORY_SOUND, i), .6); i++; if(i+1 < tottrack ) { llPreloadSound(llGetInventoryName(INVENTORY_SOUND, i+1)); } if(i == tottrack ) { llResetScript(); } } }
Any help would be great! Thanks!
_____________________
Satai Diaz Owner of SD Designs DJ for Crystal Blue @ Cafe Hailey Producer of Digital Paradise Studios & Cinema Admiral of Kazenojin Owner of SLRA
|
Alpha Zaius
llLol()
Join date: 13 Mar 2004
Posts: 1,187
|
07-09-2005 03:47
I dont know if this works or not (cant get in SL) since I wrote it in the brwoser. Give that a try and let me know if it compiles/plays all the songs 
integer play = FALSE;
soundRandom() { integer totalTracks = llGetInventoryNumber(INVENTORY_SOUND); integer randomPick = llRound(llFrand(totalTracks)); string randomSoundName = llGetInventoryName(INVENTORY_SOUND,randomPick);
llPreloadSound(randomSoundName); llllTriggerSound(randomSoundName,.6); }
default {
touch_start(integer total_number) { soundRandom(); } }
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
07-09-2005 10:18
try this: float VOLUME = 1.0; list sounds; integer curSound;
list getInventoryList(integer type) { list ret; integer i; integer num = llGetInventoryNumber(type); for (i = 0; i < num; ++i) ret += llGetInventoryName(type, i); return ret; }
randPlay() { integer numSounds = llGetListLength(sounds); // Once we're done going through the entire list // start over with a frehly randomized list. if (curSound >= numSounds - 1) { curSound = 0; sounds = llListRandomize(sounds, 1); } string soundName = llList2String(sounds, curSound); llTriggerSound(soundName, VOLUME); if (numSounds > curSound + 1) { string nextName = llList2String(sounds, curSound + 1); llPreloadSound(nextName); } ++curSound; }
default { state_entry() { sounds = llListRandomize(getInventoryList(INVENTORY_SOUND), 1); } touch_start(integer totalNum) { randPlay(); } changed(integer change) { if (change & (CHANGED_INVENTORY|CHANGED_ALLOWED_DROP)) { sounds = llListRandomize(getInventoryList(INVENTORY_SOUND), 1); curSound = 0; } } }
(Note: It might not compile, I wrote it in SciTE-ez) ==Chris
|