Linked Primitive Fader

From Second Life Wiki
Jump to navigation Jump to search

Created by Kira Komarov.

Shortnote

This is a short script I was asked by Raphael Debs to create which fades a linked primitive in and out. One possible application could be fading in and fading out a texture on a primitive by creating a screen in front of it.

It is also a good demonstration of using llSensorRepeat as a second timer (posted on the Wizardry and Steamworks page) as well as using a conditional as an in-line assignment with a switch.

Features

  • Configurable fade-in, fade-out and time between show and hide.

Setup

This script acts on the linked-primitive number 2: <lsl>

       if(!o) {
           llSetLinkAlpha(2, f-=0.1, ALL_SIDES);
           return;
       }
       llSetLinkAlpha(2, f+=0.1, ALL_SIDES);

</lsl>

If you want the script to work on a different linked primitive, just replace the 2 to the number of the linked primitive you want to fade.

Code

<lsl> ////////////////////////////////////////////////////////// // [K] Kira Komarov - 2011, License: GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html // // for legal details, rights of fair usage and // // the disclaimer and warranty conditions. // //////////////////////////////////////////////////////////

////////////////////////////////////////////////////////// // CONFIGURATION // ////////////////////////////////////////////////////////// // Change this to the time between // fade-in and fade-out events. float TIME_BETWEEN_FADES = 7; // Change this to the time it takes // to fade-out the screen. float FADE_OUT_TIME = 0.2; // Change this to the time it takes // to fade-in the screen. float FADE_IN_TIME = 0.2; ////////////////////////////////////////////////////////// // INTERNALS // ////////////////////////////////////////////////////////// integer o = -1; float f;

default {

   state_entry()
   {
       llSetTimerEvent(TIME_BETWEEN_FADES);
   }
   timer() {
       llSetTimerEvent(0);
       if(o = ~o) {
           llSensorRepeat("", NULL_KEY, ACTIVE, 0.1, f=0.0, FADE_IN_TIME);
           return;
           
       }
       llSensorRepeat("", NULL_KEY, ACTIVE, 0.1, f=1.0, FADE_OUT_TIME);
   }
   no_sensor() {
       if(f<0.0 || f>1.0) {
           llSensorRemove();
           llSetTimerEvent(TIME_BETWEEN_FADES);
           return;
       }
       if(!o) {
           llSetLinkAlpha(2, f-=0.1, ALL_SIDES);
           return;
       }
       llSetLinkAlpha(2, f+=0.1, ALL_SIDES);
   }

} </lsl>