Making a prim fade away...
|
|
Led Writer
Registered User
Join date: 12 Apr 2007
Posts: 14
|
10-08-2007 08:34
hi, I've been trying to make a prim fade away. I suppose it's the right thing to use something with llSetAlpha() for that?
So, I tried this little script of mine, which is not working.
//begin script
float alpha;
default { state_entry() { alpha = llGetAlpha(ALL_SIDES); }
touch_start(integer total_number) { llSetTimerEvent(3); } timer() { llSetAlpha(alpha-0.1, ALL_SIDES); } }
//end script
Thanks for helping.
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
10-08-2007 08:44
Need to update the alpha variable as it fades. Perhaps in the timer event handler, something like:
llSetAlpha(alpha=alpha-0.1, ALL_SIDES);
|
|
Led Writer
Registered User
Join date: 12 Apr 2007
Posts: 14
|
10-08-2007 08:59
hi, upon your suggestion, I tried the following, but it does not fade...it goes straight away
// begin script
float alpha;
default { state_entry() { alpha = llGetAlpha(ALL_SIDES); }
touch_start(integer total_number) { llSetTimerEvent(3); } timer() { llSetAlpha(alpha=alpha-0.1, ALL_SIDES); } }
// end script
any suggestions???
|
|
Buffy Wilder
Registered User
Join date: 12 Jan 2007
Posts: 16
|
10-08-2007 09:01
Try this, I've also included code to remove your timer event once its alpha has reached 0 (i.e. its invisible)
Buffy
float alpha;
default { state_entry() { alpha = llGetAlpha(ALL_SIDES); }
touch_start(integer total_number) { llSetTimerEvent(3); }
timer() { alpha = alpha - 0.1;
if (alpha < 0) { llSetTimerEvent(0); alpha = 0; }
llSetAlpha(alpha, ALL_SIDES); }
|
|
Led Writer
Registered User
Join date: 12 Apr 2007
Posts: 14
|
10-08-2007 09:05
Thanks. I did copy/paste your script, but there is no change at all! The code looks fine, but somehow its not working...
|
|
Buffy Wilder
Registered User
Join date: 12 Jan 2007
Posts: 16
|
10-08-2007 09:08
Things to check for,
1) Is the script set to run (look in the bottom left hand corner of the edit window for the script (theres a little checkbox down there).
2) Are you on script enabled land ?
3) Does the prim the script is in have the right group permissions (i.e. if on group land where only group scripts are allowed to run). Check under the edit window for permissions (first tab).
Buffy
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
10-08-2007 09:47
add just before the llSetAlpha()
llOwnerSay("alpha is "+(string)alpha);
If you don'see it saying anything, the script is not running...
|
|
Led Writer
Registered User
Join date: 12 Apr 2007
Posts: 14
|
10-08-2007 10:03
Yes, scripts are allowed and this one is running. Funny, was about to add, that i checked that, in my previous post  But...still not working. Did you manage to make this work? Thanks.
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
10-08-2007 10:24
Works for me, but I'm pretty sure we don't really want state_entry to get the alpha of ALL_SIDES... which seems to be the *sum* of the alphas of each face (who knew?). So, depending on the prim, it might take 15 seconds or so to get down to an alpha of 1.0 to start fading.
|
|
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
|
10-08-2007 17:53
Pardon a newbie scripter muddying the waters, but this works:
float alpha;
default { state_entry() { llSetAlpha(1.0, ALL_SIDES); alpha = 1.0; }
touch_start(integer total_number) { while(alpha > 0.0) { alpha = (alpha - 0.1); llSetAlpha(alpha, ALL_SIDES); llSleep(0.05); } } }
The previous script didn't work for me either - it stayed visible the length of the timer setting, then went to alpha of 0.
|
|
Led Writer
Registered User
Join date: 12 Apr 2007
Posts: 14
|
10-09-2007 06:02
Thank you very much! I managed to achieve it the other day by tweaking the following script, I found in a different thread:
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(); } } }
Now, I was wondering, if it was possible to change the fading, even when it is currently fading in or out. For example: I make it fade out, but 5 seconds later, I want to make it fade in. At the moment, this does not work, because once the fading process started, you have to wait till its done, before you can change it. I could imagine to do that by using several scripts and switching them on/off, but it would be better to do it with only one script. Is that possible?
Thanks in advance...
|
|
Stephen Zenith
Registered User
Join date: 15 May 2006
Posts: 1,029
|
10-09-2007 06:09
If you wanted to be clever, you could do it with an animated texture with decreasing alpha drawn right on it 
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
10-09-2007 09:33
Lots of possible ways to fade out and then in. For example, if your fade out is
alpha = alpha - 0.1;
then the 0.1 is just an adjustment factor, call it adj.
So, for fade out, adj = -0.1. for fade in, adj = 0.1. and your fade statement is
alpha = alpha + adj;
see? It will either increase or decrease the alpha depending on whether adj is 0.1 or -0.1.
By the way, you could also say
alpha += adj;
|