Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Smooth fading of a linked set using one script.

Nitrox Peel
Rox
Join date: 12 Jan 2005
Posts: 15
03-20-2007 07:15
Wrote a small code snippet i use to fade in and out the text display on the Rox Media Center.

It basiclly fades out or in a set nr of linked prims using one script.

Learnt alot from this forum so i figured id share it with ya all. And hopefully someone can improve it even more.

CODE

float alpha;
float fadespeed = 0.02; //This sets the speed of the fading in and out effect.

integer visible = FALSE;
integer links = 10; //Change this to how many linked objects you have.
integer linknr;


fadeout()
{
if (visible == TRUE)
{
alpha = llGetAlpha(1)*10;
do
{
++alpha;
do
llSetLinkAlpha(linknr,alpha/10,ALL_SIDES);
while((++linknr)<links);
linknr = 0;
llSleep(fadespeed);
}
while((integer)alpha<10);
visible = FALSE;
}
}
fadein()
{
if (visible == FALSE)
{
alpha = llGetAlpha(1)*10;
do
{
--alpha;
do
llSetLinkAlpha(linknr,alpha/10,ALL_SIDES);
while((++linknr)<links);
linknr = 0;
llSleep(fadespeed);
}
while(alpha>0);
visible = TRUE;
}
}

default
{
state_entry()
{
}
link_message(integer sender, integer num, string str, key id)
{
if (str == "show")
{
fadeout();

}
if (str == "hide")
{
fadein();
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
03-21-2007 04:25
/15/12/172500/1.html
_____________________
i've got nothing. ;)
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
03-21-2007 05:14
This looks fine and all, but I am curious as to certain things in this code.

You have it written to llSetLinkAlpha on each link separately using the linknmbr, when you could just use LINK_SET to do the whole thing at once.
Nitrox Peel
Rox
Join date: 12 Jan 2005
Posts: 15
03-21-2007 06:17
Your absolutely right, however in my setup i only want to fade the 10 next links for my display and not the rest of the prims. This might also be a childprim and you could add a llGetLinkNumber(); and make sure your only fading text(or whatever you wanna fade) and nothing else.

Like this :
CODE

float alpha;
float fadespeed = 0.02; //This sets the speed of the fading in and out effect.

integer visible = FALSE;
integer links = 10; //Change this to how many linked objects you have.
integer linknr;
integer thislink;

fadeout()
{
if (visible == TRUE)
{
alpha = llGetAlpha(1)*10;
do
{
++alpha;
do
llSetLinkAlpha(linknr,alpha/10,ALL_SIDES);
while((++linknr)<links);
linknr = thislink;
llSleep(fadespeed);
}
while((integer)alpha<10);
visible = FALSE;
}
}
fadein()
{
if (visible == FALSE)
{
alpha = llGetAlpha(1)*10;
do
{
--alpha;
do
llSetLinkAlpha(linknr,alpha/10,ALL_SIDES);
while((++linknr)<links);
linknr = thislink;
llSleep(fadespeed);
}
while(alpha>0);
visible = TRUE;
}
}

default
{
state_entry()
{
thislink = llGetLinkNumber();
linknr = thislink;
}
link_message(integer sender, integer num, string str, key id)
{
if (str == "show")
{
fadeout();

}
if (str == "hide")
{
fadein();
}
}
}
Furia Freeloader
Furiously Furia
Join date: 13 Dec 2005
Posts: 34
03-21-2007 12:52
I have written similar scripts for fading the alpha in and out. but be warned! If you make repeated calls to llSetAlpha you do get a fairly high lag load. Increasing the sleep time between calls seems to help.
Nitrox Peel
Rox
Join date: 12 Jan 2005
Posts: 15
03-22-2007 02:01
From: Furia Freeloader
I have written similar scripts for fading the alpha in and out. but be warned! If you make repeated calls to llSetAlpha you do get a fairly high lag load. Increasing the sleep time between calls seems to help.


Right, im not sure what you consider fairly high lag load. But after running it in a timer loop with 10linked objects fading in and out... at first it didnt even show up on the Top Scripts debug, however after about 10minutes i got lucky and got a listing at 0.002 Seconds. This is when running and not when idle.

Feel free to test and correct me if im mistaken :P