Jump to content

Help in animation triggered sound script


Korbie
 Share

Recommended Posts

Hi all, I am trying to create a script that when animation starts it triggers sound clips, similar to a moving vehicle, when the vehicle moves it triggers a sound. I was able to get this script below but it wont work for me, i tried to follow instructions but i am not sure where i made a mistake...

string gAnimUUID = "5aed16f9-53ba-57e1-f3cb-2ff36d89343f";//***THIS HAS TO BE INSERTED BY YOU***
string gSound = "";//having a sound in contents will override
//----------------------------------
integer gAnimState;
//----------------------------------
f_toggle(integer on)
{ if(on)
{ string n = llGetInventoryName(INVENTORY_SOUND,0);
if(n!="")
gSound=n;
if(gSound!="")
llLoopSound(gSound,1.0);
else
llOwnerSay("ERROR: No sound defined in script and none in object contents.
Without one or the other I cant work.");
}
else
llStopSound();
}
//----------------------------------
f_perms() //make it still operate when entering no script areas
{ if(llGetAttached())
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
}
//==============================================================
default
{ state_entry()
{ if(llGetAttached())//DEV
f_perms();
else
llOwnerSay("You must be wearing me for this to operate.");
}
attach(key id)
{ f_perms();
}
run_time_permissions(integer perm)
{ if(perm & PERMISSION_TAKE_CONTROLS)
{ f_toggle(gAnimState=FALSE);
llSetTimerEvent(0.444444);
}
}
control(key id, integer pressed, integer change)
{ //make it still operate when entering no script areas
}
timer()
{ if(-1<llListFindList(llGetAnimationList(llGetOwner()), [(key)gAnimUUID]))
{ if(!gAnimState)
f_toggle(gAnimState=TRUE);
}
else if(gAnimState)
f_toggle(gAnimState=FALSE);
}
}

Link to comment
Share on other sites

It's a LOT easier to see what 's going on in a script -- even a short one -- if you indent properly and use curly brackets throughout to mark scope.

string gAnimUUID = "5aed16f9-53ba-57e1-f3cb-2ff36d89343f";//***THIS HAS TO BE INSERTED BY YOU***string gSound = "";//having a sound in contents will override//----------------------------------integer gAnimState;//----------------------------------f_toggle(integer on){ 	if(on)	{	 	string n = llGetInventoryName(INVENTORY_SOUND,0);		if(n!="")                {		        gSound=n;                }		if(gSound!="")		{			llLoopSound(gSound,1.0);		}		else		{			llOwnerSay("ERROR: No sound defined in script and none in object contents.			Without one or the other I cant work.");		}	}	else	{		llStopSound();	}}//----------------------------------f_perms() //make it still operate when entering no script areas{ 	if(llGetAttached())	{		llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);	}}//==============================================================default{ 	state_entry()	{ 		if(llGetAttached())//DEV		{			f_perms();		}		else		{			llOwnerSay("You must be wearing me for this to operate.");		}	}	attach(key id)	{ 		f_perms();	}	run_time_permissions(integer perm)	{ 		if(perm & PERMISSION_TAKE_CONTROLS)		{			f_toggle(gAnimState=FALSE);			llSetTimerEvent(0.444444);		}	}		control(key id, integer pressed, integer change)	{ //make it still operate when entering no script areas	}	timer()	{ 		if(-1<llListFindList(llGetAnimationList(llGetOwner()), [(key)gAnimUUID]))		{ 			if(!gAnimState)			{				f_toggle(gAnimState=TRUE);			}			else if(gAnimState)			{				f_toggle(gAnimState=FALSE);			}		}	}}

So, all this script does is toggle gAnimState between TRUE and FALSE every 0.444444 seconds, which is a bit bizarre because that means it's starting and stopping the sound over and over and over again, twice a second.  I'm not sure what else you expected it to do, but it's at least doing that.  The script has nothing to do with something moving.

Link to comment
Share on other sites

Hello Korbie!

 

It looks like how your timer event is set up is the reason why it's not working. The llSetTimerEvent function is using an interval of 0.4 seconds but it's way to short to complete the sound. As soon a sound gets played, it then will stop right after the next 0.4s interval. To make it work, the script has to set a longer interval when playing the sound and reset it when finished.

And indeed, using the Insert Code feature at the editor helps us a lot reading script code. ;)

 

 

Link to comment
Share on other sites

starting with a delay... your timer is probably waiting before it fires the first time?

your call that sets the timer event should be llSetTimerEvent(0.1) ,

 then IN your timer event, reset the timer to what ever length you have , ex: llSetTimerEvent(10.0) ,

as for adding sounds, you could make a list of the sounds and instead of loopin, use llPlaySound

 and run thru the list using a count variable.

 

list sounds = [ "5aed16f9-53ba-57e1-f3cb-2ff36d89343f", " (2ndUUD) ", " ( 3rd UUID) "]

integer count = 0;

 

and in the timer, increment the count variable...

++count;

if(count > llGetListLength(sounds) )

{ count = 0; }

string curSound = llList2String(sounds,count);

 llPlaySound(curSound,1.0);

etc, etc ...

 

 

 

 

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...