Table of Contents

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 lsl page) as well as using a conditional as an in-line assignment with a switch.

Features

Setup

This script acts on the linked-primitive number 2:

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

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

Code

fader.lsl
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3      //
//  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  //
//  rights of fair usage, 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 = .2;
// Change this to the time it takes
// to fade-in the screen.
float FADE_IN_TIME = .2;
///////////////////////////////////////////////////////////////////////////
//                              INTERNALS                                //
///////////////////////////////////////////////////////////////////////////
integer o = -1;
float f;
 
default
{
    state_entry()
    {
        llSetTimerEvent(TIME_BETWEEN_FADES);
    }
 
    timer() {
        llSetTimerEvent(0);
        if(o = ~o) {
            llSensorRepeat("", NULL_KEY, ACTIVE, .1, f=.0, FADE_IN_TIME);
            return;
 
        }
        llSensorRepeat("", NULL_KEY, ACTIVE, .1, f=1.0, FADE_OUT_TIME);
    }
    no_sensor() {
        if(f<.0 || f>1.0) {
            llSensorRemove();
            llSetTimerEvent(TIME_BETWEEN_FADES);
            return;
        }
        if(!o) {
            llSetLinkAlpha(2, f-=.1, ALL_SIDES);
            return;
        }
        llSetLinkAlpha(2, f+=.1, ALL_SIDES);
    }
}