Jump to content

Script for Glow in timer


Yasojith
 Share

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

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

Recommended Posts

Hi, I'm a newbie for LSL. Trying to make a script that glow increase and decrease each faces of a prim based on timer.  (I was looking it in marketplace but couldn't such script). Here what I made so far by combining some free scripts. 

 

default
{   
 state_entry()   
  {           
   integer tFace = llSetTimerEvent(5.0);  
   }    
 
       timer() 
    {                 
 float glowVal = llList2Float( llGetLinkPrimitiveParams(LINK_THIS, [PRIM_GLOW, tFace]), 0);                   
 if( glowVal > 0.0) 
 glowVal = 0.0;          
 else glowVal = 0.2;          
 llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, tFace, glowVal]); 
   }
      }

 

This gives an error. Can anyone could help to fix that please? Thank you very much for any help.

 

 

 

Link to comment
Share on other sites

the fault is the 2 lines after else. you must put any more than a single command in braces  It is good practice to use braces anyway for clarity

 if( glowVal > 0.0) 

{
 glowVal = 0.0;    

}     
 else

{

glowVal = 0.2;          
 llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, tFace, glowVal]); 
   }

  • Thanks 1
Link to comment
Share on other sites

Actually that part of the script is fine, if you put the llSetLinkPrimitiveParamsFast command inside the bracket then it will only ever execute when glowVal = 0.2 so the glow won't turn on and off.

The real problem is that llSetTimerEvent doesn't return a value so integer tFace = llSetTimerEvent(5.0); won't work.  tFace needs to be defined either as a global variable at the start of the script, i.e. before default, or as a local variable in the event or function in which it's to be used, in this case the timer event (you can specify a particular face number or use the constant ALL_SIDES to have it change all the faces at once).  The llSetTimerEvent command should be on a different line.

Also you could get rid of the llGetLinkPrimitiveParams command and simply use an integer with a boolean value as a flag instead.

So basically your script would look something like this.

integer tFace = ALL_SIDES;
integer glow = FALSE;

default
{
    state_entry()   
    {           
        llSetTimerEvent(5.0);  
    }    
 
    timer() 
    {
        float glowVal;
        if(!glow)
            glowVal = 0.2;
        else
            glowVal = 0.0;
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, tFace, glowVal]);
        glow = !glow;
   }
}

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

2 minutes ago, Yasojith said:

Taff Nouvelle and Fluffy Sharkfin thank you so much, that helped me a lot.

You're welcome!

And, since I can't seem to sleep right now, here's an even shorter version without the need for an if statement or any variables aside from the integer flag, you just need to recast the flag from an integer to a float and divide by 5 to give you a value of either 0.2 or 0.0 depending on if the flag is TRUE or FALSE (1 or 0) and then use that as the glow value in the llSetLinkPrimitiveParamsFast command. ;)

integer glow = FALSE;

default
{
	state_entry()
	{
		llSetTimerEvent(5.0);
	}

	timer()
	{
		glow = !glow;
		llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, ALL_SIDES, (float)glow/5]);
	}
}

 

  • Like 2
Link to comment
Share on other sites

@YasojithNevertheless, I agree with Taff that it's good practice, after a conditional test always to use curly brackets (braces) even when there's only one command in the following line.

This is because, if there are no braces, the script treats the following line only as being controlled by the test.  Any following lines will execute regardless of the test result, since the script doesn't know they've got anything to do with the test.   So if there's only one line of code after the test, it doesn't make any difference, I agree, but if you later come back and add some extra code after the test (which is often the case) you have to remember to add braces or things go wrong.

That's particularly the case for me, since when a script isn't behaving as expected, I usually debug it by putting in a lot of llOwnerSay statements to tell me what's going on in the script.    If I haven't used braces in all my tests, I have to add them or this doesn't work properly, adding to the confusion.   That's something I can do without, particularly when it's late and I'm tired and a script isn't behaving.   So I always use braces after tests, since it makes life a lot easier in the long run.

 

 

  • Like 1
Link to comment
Share on other sites

18 minutes ago, Fluffy Sharkfin said:

here's an even shorter version without the need for an if statement or any variables aside from the integer flag, you just need to recast the flag from an integer to a float and divide by 5 to give you a value of either 0.2 or 0.0 depending on if the flag is TRUE or FALSE (1 or 0) and then use that as the glow value in the llSetLinkPrimitiveParamsFast command. ;)


integer glow = FALSE;

default
{
	state_entry()
	{
		llSetTimerEvent(5.0);
	}

	timer()
	{
		glow = !glow;
		llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, ALL_SIDES, (float)glow/5]);
	}
}

 

Or, if you want another entry in the Even Shorter Sweepstakes:
 

float glow;

default
{
    state_entry()
    {
        llSetTimerEvent(5.0);
    }

    timer()
    {
        llSetLinkPrimitiveParams(LINK_THIS, [PRIM_GLOW, ALL_SIDES, 0.2 * (glow = !glow)]);
    }
}

:)

And yes, always use brackets.

  • Like 2
  • Haha 1
Link to comment
Share on other sites

 

4 hours ago, Rolig Loon said:

Or, if you want another entry in the Even Shorter Sweepstakes:
 


float glow;

default
{
    state_entry()
    {
        llSetTimerEvent(5.0);
    }

    timer()
    {
        llSetLinkPrimitiveParams(LINK_THIS, [PRIM_GLOW, ALL_SIDES, 0.2 * (glow = !glow)]);
    }
}

:)

And yes, always use brackets.

 

Or how about applying a small blank texture with this for an alpha channel ...

59ff631484f91_emmisivemaskalphachannel.jpg.fcdea4de6a48a98594e17b6d8ef75e38.jpg

then setting the Alpha mode to Emissive mask and the Glow to a value of 0.20 and then all you'd need in the script would be...

default
{
    state_entry()
    {
        llSetTextureAnim(ANIM_ON|LOOP, ALL_SIDES, 2, 1, 0, 2, 0.2);
    }
}

:)

 

And yes, always always always use brackets! :D

Edited by Fluffy Sharkfin
removed duplicate image
  • Haha 1
Link to comment
Share on other sites

Fluffy Sharkfin, Innula Zenovka, Rolig Loon again many thanks for the nice advises. So I added few modifications (of cause using some other free scripts, I'm not such genius as you guys) for the script by making it glow slowly and reduce the glow also slowly. Its more like star blinking effect. Here is the script.

 

integer is_on = FALSE;
float glow = 0.1;

default
{
    state_entry()   
    {           
        llSetTimerEvent(2.0);  
    }    
 
    timer() 
    {
         if(!is_on)
        {
            float i;
            for(i = 0.050; i < glow; i += 0.010 )
            {
                llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, i]);
                //llSleep(1.0);
            }
            is_on = TRUE;
        }
    
   else
    
        if(is_on)
        {
            float i;
            for(i = glow; i > 0.050; i -= 0.010 )
            {
                llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, i]);
                //llSleep(1.0);
            }
            llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 0.05]);
            is_on = FALSE;
            llResetScript();
            
        }
   }
}

 

The script is working. But the problem is it looks laggy. I pressed Ctrl+Alt+Shift+i and saw even red boxes floating from the script. Is there a way to make the above script more effective and avoid that red boxes floating? 

 

 

Edited by Yasojith
Link to comment
Share on other sites

19 minutes ago, Yasojith said:

Is there a way to make the above script more effective and avoid that red boxes floating? 

Yes, get rid of the for loops in your timer event. The system will sail through them almost instantaneously.  Meanwhile, you are adding steps that will make very little difference, visually, and are adding unnecessarily to script time.  If you really want to make a smooth transition from glow to no-glow and vice versa, use successive steps with your timer event to do it. It's not a good idea to overuse fast timers, but triggering your timer in 0.4 second intervals and changing glow by 0.01 each time will let you go from glow = 0.00 to glow = 0.05 (or the reverse) in 2 seconds.   While you're at it, think of a better way to reverse direction than resetting the script.

Link to comment
Share on other sites

You can test with this, and change the ..amount .. variable till you get the speed you want?

The timer is reset in the user function after the effect has completed.

 

float amount = 0.0005;
float x = 0.0;  
integer k;       
pingpong()
{
    for( ; x < 0.9; x += amount)
    {  llSetLinkPrimitiveParamsFast(LINK_THIS,
       [PRIM_GLOW, ALL_SIDES,x ]);
    }
    for( ; x > 0.1; x -= amount)
    {  llSetLinkPrimitiveParamsFast(LINK_THIS,
       [PRIM_GLOW, ALL_SIDES,x ]);
    }
    llSetTimerEvent(0.2);
}
default
{
    state_entry()
    {  llSetLinkPrimitiveParamsFast(LINK_THIS,
       [PRIM_GLOW, ALL_SIDES,0.01 ]);
    }
    touch_start(integer total_number)
    { if(k = !k)
      {  llSetTimerEvent(0.2);
      }
      else 
      {   llSetTimerEvent(0.0);
          llSetLinkPrimitiveParamsFast(LINK_THIS,
          [PRIM_GLOW, ALL_SIDES,0.0 ]);
      }
    }
    timer()
    {  llSetTimerEvent(0.0);
       pingpong();
    }
}

 

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

@Yasojith If you're trying to achieve a smooth transition (i.e. pulsing effect) and are only using a blank texture on the object rather than a specific image then I would definitely recommend exploring the llSetTextureAnim approach rather than attempting to do it all via script.

Texture Animation is a client-side effect so is far more resource friendly and also won't suffer from any slowdown on laggy sims where lots of other scripts are eating up cpu time.  Additionally since the intensity of the glow is determined by the value of the pixels in the alpha channel of a texture you may find it simpler to set up more complex transitions and effects in a bitmap editor using gradients.

For example:

default
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_ALPHA_MODE, ALL_SIDES, PRIM_ALPHA_MODE_EMISSIVE, 0, 
            PRIM_GLOW, ALL_SIDES, 0.2, 
            PRIM_TEXTURE, ALL_SIDES, "5c2f0866-56b7-8ea3-00cf-cca31a07a220", <1,1,0>, <0,0,0>, 0.0]);
            
        llSetTextureAnim(ANIM_ON|LOOP, ALL_SIDES, 128, 1, 0, 128, 32);
    }
}

uses a 128 x 32 plain white texture with an alpha channel like this 5a00236192ec8_EmissiveGradient1.jpg.e784bb00b4cf9d3064077551c990d110.jpg to produce a steady transition from 0% to 100% and back to 0% (the actual amount of glow is determined by the settings for the prim, i.e. PRIM_GLOW, ALL_SIDES, 0.2, however emissive mask mode affects the Full Bright value of the prim so it will appear slightly brighter than using only glow).

Changing the PRIM_TEXTURE settings to

PRIM_TEXTURE, ALL_SIDES, "79de213f-bc72-748f-d6e1-285e58aff1a4", <1,1,0>, <0,0,0>, 0.0]);

would use a texture with an alpha channel like this 5a002a30ba901_EmissiveGradient2.jpg.643263a09a3363bacf20cdf78aadea4f.jpg which results in a faster transition and shorter pulse with a longer pause in between.

Similarly changing the PRIM_TEXTURE settings to

PRIM_TEXTURE, ALL_SIDES, "2341f9d9-b7a3-e18f-c294-d2c24106de7f", <1,1,0>, <0,0,0>, 0.0]);

uses a texture with an alpha channel like this 5a002d159ff09_EmissiveGradient3.jpg.59e911768aba264dc6d54f1d2e4003a4.jpg which would give a 2 second pause followed by an instant transition to max glow then a 2 second fade back to zero.

And finally changing the PRIM_TEXTURE settings to

PRIM_TEXTURE, ALL_SIDES, "1be86627-0563-ad17-0ed5-5006176d231b", <1,1,0>, <0,0,0>, 0.0]);

uses a texture with this alpha channel 5a002ffc2cee2_EmissiveGradient4.jpg.fbfdfc53be48d64aa061982829107c33.jpg to produce 3 short half-second pulses at 50% glow (50% grey), followed by a 1 second pulse at 100% glow (white) with a slow fade in and faster fade out.

 

As you can see from the above examples you can easily control the timing and intensity of the pulses simply by adjusting the gradient that you use in the alpha channel of the texture, and since the script only runs once and then stops it uses no additional cpu time (in fact since texture animation is treated as a property of the prim you can even remove the script once its been run and the texture will continue animating regardless).

  • Like 2
  • Thanks 2
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2375 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...