Loop sound on touch - Stop sound on touch
|
Billy Trenton
Registered User
Join date: 12 Apr 2007
Posts: 3
|
04-30-2007 12:42
Hello,
This script i wrote (put together, me no good scripter)is playing 1 sound on touch from content of 1 object that changes color during a float time. So far i figured it out (see script below).
My problem is I want to play sound on touch and loop the sound endless, and stop it when the button is touched again. Also the color has to change back only when the button is touched again.
I treid to put llLoopSound() into the script together with llStopSound(), but i did not get it right, got errors all the time saving it.
Another (not so big) issue is : I have 16 buttons (16prims), all linked, all have different sounds in it and so far it works good with the script below. But I like to preLoad the sounds all in one time touching one other button, like an ON/OFF button... is that possible?
And the volume problem? I like to send the sounds all over my parcel instead of a few meters. I read it was not possible, but is there some new info about?
Thanks in advance, Billy Trenton
SCRIPT:
float length = 3.8; vector off = < 1., 1., 1.>; vector on = < 1., 0., 0.>;
default { state_entry() { llPreloadSound( "Synth 001" ); llSetColor(off, ALL_SIDES); }
touch_start( integer total_num ) { llPlaySound( "Synth 001", 1.0 ); llSetColor(on, ALL_SIDES); llSleep(length); llSetColor(off, ALL_SIDES); } }
|
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
|
04-30-2007 14:55
Try llLoopSound()
And pair it with llStopSound()
_____________________
--AeonVox--Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
|
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
|
04-30-2007 15:23
First...just for future reference...enclosing your code in [ php ] and [ /php ] (without the spaces) tags helps us all to read it more easily. float length = 3.8; vector off = < 1., 1., 1.>; vector on = < 1., 0., 0.>;
integer on;
default { state_entry() { llPreloadSound( "Synth 001" ); llSetColor(off, ALL_SIDES); }
touch_start( integer total_num ) { if(on != TRUE) { llLoopSound( "Synth 001", 1.0 ); llSetColor(on, ALL_SIDES); on = TRUE; } else { llStopSound(); // I did NOT check this function, just threw it in. Don't know if arguments are needed inside the parens. llSetColor(off, ALL_SIDES); on = FALSE; } } }
By the way...anyone know factually if the method of declaring a variable opposite by: on = !on works in SL?
_____________________
--AeonVox--Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
|
Rusty Satyr
Meadow Mythfit
Join date: 19 Feb 2004
Posts: 610
|
04-30-2007 15:34
I've been having trouble with sound lately.... but if you're getting compile errors, make sure your "Synth 01" sound is actually stored in the contents of the prim with the script first.
There is an llTriggerSoundLimited() which is SUPPOSED to define a box in which the sound can be heard, but I only hear sounds if my avatar AND my camera are really close to the prim emitting the sound.
My whiny bitter opinion is that linden lab decided sound is a griefer tool and they've handicapped it tremendously. I would dearly like to be proven wrong.
|
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
|
04-30-2007 17:00
From: Rusty Satyr My whiny bitter opinion is that linden lab decided sound is a griefer tool and they've handicapped it tremendously. I would dearly like to be proven wrong.
I wouldn't doubt you...and...in fact...I have been in SL with my sound off since...oh...the first 2 weeks of my membership back in 05. See...there are these things called gestures...and they emit sounds...and OMG is it annoying...
_____________________
--AeonVox--Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
|
Cherry Hainsworth
Registered User
Join date: 31 Jul 2006
Posts: 125
|
04-30-2007 17:29
Yep, llStopSound should work without parameters. I wonder about your 'on' definition, though? I have no idea whether it's better to use vectors for such things, but - as an admittedly poor scripter - I tend to use either a string or an integer for bitwise params. Have you tried it with "on" as a string to be checked? From: someone By the way...anyone know factually if the method of declaring a variable opposite by:
on = !on Well ... it does if it's a string  Cherry
|
Billy Trenton
Registered User
Join date: 12 Apr 2007
Posts: 3
|
marvelouse  !
05-01-2007 13:20
Thanks Kenn, script is running cool. I had to change the integer (on) name cause it gives an error on the vector (on) name. But after that it works great. Thanks all for feedback. And about the volume thing we have to wait till Linden give other options,  . And about the preload all thing, i just click them all one time when starting, hehehe. Cheers... Greetz Billy.
|
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
|
05-01-2007 13:40
Whoops...I didn't even catch that there was a vector called on...hah...shows how smart I can be sometimes. Yea...can't double-declare a variable name. Sorry about that, but glad you got the script working.
_____________________
--AeonVox--Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
|
Billy Trenton
Registered User
Join date: 12 Apr 2007
Posts: 3
|
05-01-2007 15:12
No problem Kenn, keeps me sharp  , but i use this options now in different script to stop and start things very handy. Now i try to figure out how to trigger with a object ... another object, so it goes turning and stop. Is it possible ? Greetz, Billy
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
05-02-2007 00:01
From: Billy Trenton No problem Kenn, keeps me sharp  , but i use this options now in different script to stop and start things very handy. Now i try to figure out how to trigger with a object ... another object, so it goes turning and stop. Is it possible ? Greetz, Billy Objects cannot "touch" other objects, they can only collide with them. So if you require that another object trigger the system in the same manner use a collision_start event instead of a touch. The code will be identical. If your obejcts are stationary, i.e. will never collide, then you could switch to chat activation using a listen.
|
Vallera Nexen
Registered User
Join date: 16 Jan 2009
Posts: 5
|
04-07-2009 10:16
Can somebody post the corrected version of this script because I dont have a clue how to fix it
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
04-07-2009 10:44
From: Vallera Nexen Can somebody post the corrected version of this script because I dont have a clue how to fix it Ooo! A necropost. The only thing keeping this one from working, I think, is that the scripter has used the variable "on" to mean two different things, so they collide with each other. You'll notice that post #6 made the same observation. It ought to work OK if you just give the integer variable a new name, like "switch." Be sure that you rename it in the three places where it's used in the body of the script, as well as in the type declaration at the top and you should be fine. I think. 
|
Vallera Nexen
Registered User
Join date: 16 Jan 2009
Posts: 5
|
04-07-2009 17:18
ok, I think I got it figured out after a little trial and error. it took me awhile since I am no scripter, but i don't get any error messages when I save the script now, so i think its good now. thanks very much for the prompt reply.
|
Vallera Nexen
Registered User
Join date: 16 Jan 2009
Posts: 5
|
04-07-2009 18:51
I thought I had it figured out, but it only works if I click on the prim that the script is in...how do I make it work for a multi prim object?
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
04-07-2009 19:03
If the prims are linked, touching any prim in the linkset should have the same effect as touching the prim with the script in it. EDIT: It occurs to me that you might be asking how to make the color of ALL prims in the linkset change when you click on any prim in the linkset. If that's the case, just replace the two llSetColor statements in the script with llSetLinkColor statements that look like .... llSetLinkColor(LINK_SET, on,ALL_SIDES);
and llSetLinkColor(LINK_SET,off,ALL_SIDES);
|
Vallera Nexen
Registered User
Join date: 16 Jan 2009
Posts: 5
|
04-07-2009 19:38
I dont want it to change colors, but no it doesnt work when i click on any prim, it only works when i click on the one prim that the script and sound file is in
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
04-07-2009 20:00
Then the prims must not be linked. There's no other reason why you shouldn't be able to touch any prim to make it work. You did link them, didn't you?
|
Vallera Nexen
Registered User
Join date: 16 Jan 2009
Posts: 5
|
04-07-2009 20:32
From: Rolig Loon Then the prims must not be linked. There's no other reason why you shouldn't be able to touch any prim to make it work. You did link them, didn't you? Yes, of course. I thought of a work around to my problem. I can just put the fire inside a bigger invisible cube and link them so that the cube is the root prim, then I can click anywhere on it and the flame will start/stop and the sound will start/stop simultaneously.
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
04-07-2009 21:46
and actually the line:
if(on != TRUE)
also works as
if(!on)
and yes:
on = !on
works to make it opposite
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
04-08-2009 05:30
From: Vallera Nexen Yes, of course. I thought of a work around to my problem. I can just put the fire inside a bigger invisible cube and link them so that the cube is the root prim, then I can click anywhere on it and the flame will start/stop and the sound will start/stop simultaneously. Flame? What flame? This script doesn't have anything to do with a flame. All it does is turn sound on and off and change the color of the prim it's in. If you have a flame, it's being controlled by a particle script somewhere, not by this script. 
|
Dekka Raymaker
thinking very hard
Join date: 4 Feb 2007
Posts: 3,898
|
04-09-2009 04:17
From: Rolig Loon Flame? What flame? This script doesn't have anything to do with a flame. All it does is turn sound on and off and change the color of the prim it's in. If you have a flame, it's being controlled by a particle script somewhere, not by this script.  maybe this script is so hot it burns those prims 
|