Torin Golding
Misanthropic Humanist
Join date: 13 Sep 2005
Posts: 41
|
10-31-2005 14:40
I've searched the Wiki's info for an hour and experimented for another two but I just can't figure out the scripting terms. (there's a reason I'm in the humanities  ) I just want to have an item that when I click it, it plays one of the sounds in it randomly. I looked at how some free environmental sound scripts in my inventory handled the llFrand command, and experimented with assigning one sound to a number and asking it to play that sound if it returns that number, but can't figure it out. Does anyone out there know a better (simpler!) way to achieve the same effect, or know of a simple script to have an item play a random sound in its inventory when the item is clicked? Thanks in advance! -Torin
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
10-31-2005 14:55
integer numSounds;
default { on_rez(integer param) { llResetScript(); }
state_entry() { numSounds = llGetInventoryNumber(INVENTORY_SOUND); }
touch_start(integer num) { llPlaySound(llGetInventoryName(INVENTORY_SOUND, llFloor(llFrand(numSounds))), 0.5); } }
I think that should do it. This won't check for sound clips added/removed after the script has started, so reset the script if you change inventory. also, I've seen the touch become disabled on a script reset sometimes. If that happens, set scripts to not running followed by running, and that should clear it. And here's a touch_start that breaks it down into individual steps and is easier to read, if that one doesn't make sense: touch_start(integer num) { float randomFloat = llFRand(numSounds); integer randomInt = llFloor(randomFloat); string randomSoundFileName = llGetInventoryName(INVENTORY_SOUND, randomInt); llPlaySound(randomSoundFileName, 0.5); }
|
Torin Golding
Misanthropic Humanist
Join date: 13 Sep 2005
Posts: 41
|
11-01-2005 14:02
Thanks Ziggy! It works wonderfully!!
|