Playing sound with a sensor?
|
|
Bubster Box
Registered User
Join date: 12 Jan 2007
Posts: 16
|
09-16-2008 05:23
Have been trying to put together a script that set off a sounds when someone gets close to a object, but it only works now and again, and also only seem to react to me, and no one else.
float LOUDNESS = 0.5; float sensorRange = 5.0;
default { state_entry() { llSensorRepeat("", NULL_KEY, AGENT, sensorRange, TWO_PI, 10); }
sensor(integer num_detected) { integer sounds = llGetInventoryNumber(INVENTORY_SOUND);
if ( sounds <= 0 ) return;
string soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(sounds)) ); if ( soundname != "" ) { llPlaySound( soundname, LOUDNESS ); } } }
Any ideas what can be done?
Thanks
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
09-16-2008 05:55
It takes time to download any sound to the client, could have something to do with it. Each new sound takes a new download and any new client need to download before the sound is played.
_____________________
From Studio Dora
|
|
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
|
09-16-2008 08:57
Not sure if it'll help but I think you need llPreloadSound(string sound)
|
|
Bubster Box
Registered User
Join date: 12 Jan 2007
Posts: 16
|
09-16-2008 09:10
From: Ron Khondji Not sure if it'll help but I think you need llPreloadSound(string sound) That is a good idea. Will try to put it in there. But still it only seem to work for me and noone else??
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
09-16-2008 09:12
edit: never played with sounds - sorry, can't help there.. I wouldn't go hitting up the inventory on every single sensor return.. Just have a global for the number of sounds and update it when the inventory changes.. Maybe something like this: float LOUDNESS = 0.5; float sensorRange = 5.0; float sensorRate = 10.0; integer soundCount;
default { state_entry() { llSensorRepeat("", NULL_KEY, AGENT, sensorRange, TWO_PI, sensorRate); soundCount = llGetInventoryNumber(INVENTORY_SOUND); }
changed (integer mask) { if (mask & CHANGED_INVENTORY) { soundCount = llGetInventoryNumber(INVENTORY_SOUND); } }
sensor(integer num_detected) { if (soundCount <= 0) { return; }
string soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(soundCount))); if ( soundname != "" ) { llPlaySound( soundname, LOUDNESS ); } } }
_____________________
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
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
09-17-2008 07:10
hmm, the preload sound looks like it might be an ok funtion if you were using only a couple certain sounds. but you're wanting to play a random sound on each sensor event. while a sensor is already hell on the server, preloading a long list of sounds probably isn't good for it either. also the index for the first sound is always 0. but you're basing the random number on how many sounds are in the list. so if you have 1 sound in the list and it happens to choose 1 instead of 0 on the random number, it won't play anything. so it should be:
string soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(soundCount-1)));//adding minus 1 to the soundcount makes it choose a number betweeen 0 and the last index number instead of 0 and the number of sounds
|
|
Bubster Box
Registered User
Join date: 12 Jan 2007
Posts: 16
|
09-17-2008 07:19
Got it working now. Thanks for all the help I got from you guys!!
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
09-17-2008 07:20
this should work hopefully From: someone float LOUDNESS = 0.5; float sensorRange = 5.0; float sensorRate = 10.0; integer soundCount; integer lastsndindex;
default { state_entry() { llSensorRepeat("", NULL_KEY, AGENT, sensorRange, TWO_PI, sensorRate); soundCount = llGetInventoryNumber(INVENTORY_SOUND); lastsndindex = soundcount - 1; }
changed (integer mask) { if (mask & CHANGED_INVENTORY) { soundCount = llGetInventoryNumber(INVENTORY_SOUND); lastsndindex = soundcount - 1; } }
sensor(integer num_detected) { if (soundCount <= 0) { return; }
string soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(lastsndindex))); if ( soundname != "" ) { llPlaySound( soundname, LOUDNESS ); } } }
|
|
Ligeia Westwick
Registered User
Join date: 1 Jul 2006
Posts: 3
|
Play Once Only?
10-21-2008 13:03
I was looking for a similar script to this for some Halloween objects. Ruthven's script works but the sound keeps repeating. Is it possible to play the sound only once while the avi is in range - so they have to move to trigger it again? Thanks
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
10-21-2008 13:32
that would be a little more complicated as far as using the sensor is concerned. you would need to record the avi's position, and then if they're picked up in the sensor again, check to see if it's the same position or not. you could try a flat prim they have to walk on and use a collision event
|
|
Ligeia Westwick
Registered User
Join date: 1 Jul 2006
Posts: 3
|
10-21-2008 13:47
Ah ok, well I will put this at the bottom of my to-do list then. Thanks Ruthven )
|
|
Cappy Frantisek
Open Source is the Devil!
Join date: 27 Oct 2006
Posts: 400
|
10-22-2008 06:07
From: Ruthven Willenov that would be a little more complicated as far as using the sensor is concerned. you would need to record the avi's position, and then if they're picked up in the sensor again, check to see if it's the same position or not. you could try a flat prim they have to walk on and use a collision event are collisions reliable again?
|