Jump to content

Combining Scripts


CataeaAstrielle
 Share

You are about to reply to a thread that has been inactive for 280 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello! I am BRAND new to scripting, and wrote up two separate scripts that I'm trying to now combine to get a candle flame to animate, toggle on and off by touch, and glow (also toggled). I keep getting a syntax error and just have no idea where I'm going wrong. I'd LOVE to have the script put in the object itself and not just the specific face in the linkset, but that seems beyond my understanding at this point. Any help would be greatly appreciated.

integer OFF = TRUE;

integer toggleState = 0;    // 0: Normal state, 1: Active state
integer faceToToggle = ALL_SIDES;   // Replace with the face number you want to control

default
{
state_entry()
{
llSetTextureAnim (ANIM_ON | LOOP, ALL_SIDES, 5, 2, 0, 0,14.0);
llSetAlpha(1.0, ALL_SIDES);
}        
on_rez(integer start_param)
{
llResetScript();
}

touch_start(integer num)
{
if(llDetectedKey(0) == llGetOwner()) 
{
if(OFF) 
{
llSetAlpha(1.0, ALL_SIDES);

OFF = FALSE;
{
        // Toggle between states on touch
        toggleState = 1 - toggleState;
{
            // Turn off glow, set full bright to false, set transparency to 100
            llSetPrimitiveParams(
            [PRIM_GLOW, faceToToggle, 0.0, 
            PRIM_FULLBRIGHT, faceToToggle, FALSE]);
            llSetLinkAlpha(LINK_THIS, 0.0, faceToToggle);
}
else
{
llSetAlpha(0.01, ALL_SIDES);
OFF = TRUE;
{
            // Turn on glow, set full bright to true, set transparency to 0
            llSetPrimitiveParams(
            [PRIM_GLOW, faceToToggle, 0.3, 
            PRIM_FULLBRIGHT, faceToToggle, TRUE]);
            llSetLinkAlpha(LINK_THIS, 1.0, faceToToggle);
} 

 

Link to comment
Share on other sites

integer OFF = TRUE;
// this variable is never read, remove it:
//integer toggleState = 0;    // 0: Normal state, 1: Active state
integer faceToToggle = ALL_SIDES;   // Replace with the face number you want to control

default
{
	state_entry()
	{
		llSetTextureAnim (ANIM_ON | LOOP, ALL_SIDES, 5, 2, 0, 0,14.0);
		llSetAlpha(1.0, ALL_SIDES);
	}        
	on_rez(integer start_param)
	{
		llResetScript();
	}

	touch_start(integer num)
	{
		if(llDetectedKey(0) != llGetOwner()) return; // some would say this is bad form, but IMO it's more neat than enclosing the rest of the event in a section.
		OFF = !OFF; // because each condition set it to the opposite value, it makes more sense to reverse it before the if clause.
        // ^ roughly the same as OFF = 1-OFF;
		if(OFF) 
		{
			llSetAlpha(1.0, ALL_SIDES);
			// Toggle between states on touch
			// Turn off glow, set full bright to false, set transparency to 100
			llSetPrimitiveParams(
			[	PRIM_GLOW, faceToToggle, 0.0, 
				PRIM_FULLBRIGHT, faceToToggle, FALSE
			]);
			llSetLinkAlpha(LINK_THIS, 0.0, faceToToggle);
		}
		else
		{
			llSetAlpha(0.01, ALL_SIDES);
			// Turn on glow, set full bright to true, set transparency to 0
			llSetPrimitiveParams(
			[	PRIM_GLOW, faceToToggle, 0.3, 
				PRIM_FULLBRIGHT, faceToToggle, TRUE
			]);
			llSetLinkAlpha(LINK_THIS, 1.0, faceToToggle);
		}
	}
} 

is how it might look with better indentation and a few fixes. I haven't tested it.

Link to comment
Share on other sites

9 hours ago, CataeaAstrielle said:

however the states seem to be sequential and not simultaneous.

search/ replace

"llSetAlpha(" -> "llSetLinkAlpha(LINK_THIS, "

"llSetPrimitiveParams( " -> "llSetLinkPrimitiveParamsFast(LINK_THIS, "

some 'older functions' have a built in delay. Without the delay it should look like things that happen very rapidly in succession happen at the same time.

ETA: llSetAlpha doesn't actually have a delay, so that search/replace is unnecessary.

Edited by Quistess Alpha
  • Thanks 1
Link to comment
Share on other sites

6 hours ago, Quistess Alpha said:

search/ replace

"llSetAlpha(" -> "llSetLinkAlpha(LINK_THIS, "

"llSetPrimitiveParams( " -> "llSetLinkPrimitiveParamsFast(LINK_THIS, "

some 'older functions' have a built in delay. Without the delay it should look like things that happen very rapidly in succession happen at the same time.

ETA: llSetAlpha doesn't actually have a delay, so that search/replace is unnecessary.

Thank you so much! I appreciate all your help. So much to learn!

Link to comment
Share on other sites

On 12/14/2023 at 1:53 AM, Quistess Alpha said:
integer OFF = TRUE;
// this variable is never read, remove it:
//integer toggleState = 0;    // 0: Normal state, 1: Active state
integer faceToToggle = ALL_SIDES;   // Replace with the face number you want to control

default
{
	state_entry()
	{
		llSetTextureAnim (ANIM_ON | LOOP, ALL_SIDES, 5, 2, 0, 0,14.0);
		llSetAlpha(1.0, ALL_SIDES);
	}        
	on_rez(integer start_param)
	{
		llResetScript();
	}

	touch_start(integer num)
	{
		if(llDetectedKey(0) != llGetOwner()) return; // some would say this is bad form, but IMO it's more neat than enclosing the rest of the event in a section.
		OFF = !OFF; // because each condition set it to the opposite value, it makes more sense to reverse it before the if clause.
        // ^ roughly the same as OFF = 1-OFF;
		if(OFF) 
		{
			llSetAlpha(1.0, ALL_SIDES);
			// Toggle between states on touch
			// Turn off glow, set full bright to false, set transparency to 100
			llSetPrimitiveParams(
			[	PRIM_GLOW, faceToToggle, 0.0, 
				PRIM_FULLBRIGHT, faceToToggle, FALSE
			]);
			llSetLinkAlpha(LINK_THIS, 0.0, faceToToggle);
		}
		else
		{
			llSetAlpha(0.01, ALL_SIDES);
			// Turn on glow, set full bright to true, set transparency to 0
			llSetPrimitiveParams(
			[	PRIM_GLOW, faceToToggle, 0.3, 
				PRIM_FULLBRIGHT, faceToToggle, TRUE
			]);
			llSetLinkAlpha(LINK_THIS, 1.0, faceToToggle);
		}
	}
} 

is how it might look with better indentation and a few fixes. I haven't tested it.

integer OFF = TRUE;
// this variable is never read, remove it:
//integer toggleState = 0;    // 0: Normal state, 1: Active state
integer faceToToggle = ALL_SIDES;   // Replace with the face number you want to control

default
{
	state_entry()
	{
		llSetTextureAnim (ANIM_ON | LOOP, ALL_SIDES, 5, 2, 0, 0,14.0);
		llSetAlpha(1.0, ALL_SIDES);
	}        
	on_rez(integer start_param)
	{
		llResetScript();
	}

	touch_start(integer num)
	{
		if(llDetectedKey(0) != llGetOwner()) return; // some would say this is bad form, but IMO it's more neat than enclosing the rest of the event in a section.
         //OFF = !OFF; // because each condition set it to the opposite value, it makes more sense to reverse it before the if clause.
        // ^ roughly the same as OFF = 1-OFF;
		//if(OFF) 
		{
			llSetAlpha(1.0-!(OFF=!OFF)*0.09, ALL_SIDES);
			// Toggle between states on touch
			// Turn off glow, set full bright to false, set transparency to 100
			llSetPrimitiveParams(
			[	PRIM_GLOW, faceToToggle,!OFF*0.3, 
				PRIM_FULLBRIGHT, faceToToggle,!OFF]);
			llSetLinkAlpha(LINK_THIS,!OFF, faceToToggle);
		}
		/*else
		{
			llSetAlpha(0.01, ALL_SIDES);
			// Turn on glow, set full bright to true, set transparency to 0
			llSetPrimitiveParams(
			[	PRIM_GLOW, faceToToggle, 0.3, 
				PRIM_FULLBRIGHT, faceToToggle, TRUE
			]);
			llSetLinkAlpha(LINK_THIS, 1.0, faceToToggle);
		}*/
	}
} 
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 280 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...