|
ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
|
03-29-2008 15:26
//Script ramdomly selects a sound and plays it every 60-80 seconds list gLstSounds = ["UUID 1","UUID 2", "ETC."]; // this is a list of the sound UUID's fPlayRandom() { llTriggerSound( llList2String( llListRandomize( gLstSounds, 1 ), 0 ), 1.0); }// llTriggerSound call placed inside of a function which //can be called by the touch even or the timer. //This randomly picks one of the sounds from the list to play. default { state_entry() { fPlayRandom(); // calls for the function to run llSetTimerEvent(llFrand(60)+20); // sets time for timer() below, random time between 60-80 seconds } touch_start(integer total_number) // randomly will play one of those sounds each time you touch it { fPlayRandom();// calls for the function to run } timer() //plays as frequently as dictated by the llSetTimer call in state_entry { fPlayRandom();// calls for the function to run }
}
_____________________
 VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30 http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240 http://shop.onrez.com/Archtx_Edo
|
|
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
|
Library bump
04-03-2008 07:45
_____________________
i've got nothing. 
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
04-03-2008 07:51
Maybe I'm missing something here but why randomize the list each time?
Wouldn't it be friendlier to leave the list itself alone and pick some random index into it?
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
|
04-03-2008 08:14
From: Meade Paravane Maybe I'm missing something here but why randomize the list each time?
Wouldn't it be friendlier to leave the list itself alone and pick some random index into it? Definitely, something like fPlayRandom() { float randomSound; randomSound = llFrand((float)llGetInventoryNumber(INVENTORY_SOUND)-1); llTriggerSound(llList2String(gLstSounds,(integer)randomSound)); }
If you have a list with 100 sounds and have to randomize it everytime you call the function you will have a lack of performance.
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
04-03-2008 08:32
That or build the list in state_entry and keep a global int around for the length. Maybe with a changed event that rebuilds the list as the owner adds/removes sounds from it. That way, you wouldn't have to query the object inventory count each time either...
Or if it's a static list of UUIDs, like the OP has it, just remember that list length in state_entry.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
04-03-2008 09:31
From: Meade Paravane Maybe I'm missing something here but why randomize the list each time?
Wouldn't it be friendlier to leave the list itself alone and pick some random index into it? Definitely. Randomizing a list takes time on the order of the size of the list ( O(n) ). Picking a random element only takes constant time ( O(1) ).
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-04-2008 10:41
if it's applied to a built list of drop in sounds (unlike above) it takes less effort just to randomize the list. plus given the time between sounds, it's not really a big deal as far as execution time, but much simpler to write.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|