Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Opacity Changer

Lou Hoodoo
My <3 Beats 4 Boo Hoodoo
Join date: 5 Jan 2005
Posts: 25
08-22-2005 14:45
Can anybody plz drop me an opacity changing script that changes according to the opacity amount u say? thx
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
09-25-2005 19:37
Just use llSetAlpha.

CODE

default
{
state_entry()
{
llSetAlpha( 0, ALL_SIDES );
}
}
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
09-26-2005 01:02
And listen event.
CODE
default
{
state_entry()
{
llListen( 1, "", NULL_KEY, "" );
}
listen( integer channel, string name, key id, string message )
{
if (llSubStringIndex(message, "Opacity ") == 0)
{
llSetAlpha((float)(llGetSubString(message, 7, llStringLength(message))), ALL_SIDES);
}
}
}
This uses channel 1. So you have to say like, "/1Opacity 0.5".
_____________________
:) Seagel Neville :)
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
09-26-2005 02:45
Even better, now with a touch menu, removes listener after being idle a minute, and changes opacity of chil prims, too:

CODE

integer handle;
integer channel;
float opacity;

default
{
state_entry() { opacity = llGetAlpha(0); }

touch_start(integer c)
{
if (llDetectedKey(0) != llGetOwner()) return;

llListenRemove(handle);
channel = (integer)llFrand(5000000) - 6000000;
handle = llListen(channel, "", llGetOwner(), "");

llDialog(llGetOwner(), "Change opacity:", ["-", "Exit", "+"], channel);
llSetTimerEvent(60.0);
}

timer()
{
llListenRemove(handle);
llSetTimerEvent(0.0);
}

listen(integer c, string n, key id, string msg)
{
if (msg == "+") { opacity += 0.1; if (opacity > 1.0) opacity = 1.0; } else
if (msg == "-") { opacity -= 0.1; if (opacity < 0.0) opacity = 0.0; } else return;

llSetLinkAlpha(LINK_SET, opacity, ALL_SIDES);

llDialog(llGetOwner(), "Change opacity:", ["-", "Exit", "+"], channel);
llSetTimerEvent(60.0);
}
}
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Ledje Gorky
Registered User
Join date: 1 Jun 2005
Posts: 126
09-26-2005 04:52
This seems a very handy script.
But what do you actually use it for?
Ive got my own ideas, but i dont wanna appear stupid :)
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
09-26-2005 05:02
Which script ? The last one ? I just wrote it up on the spot :o
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Slayd Lemieux
Registered User
Join date: 9 Jul 2005
Posts: 29
09-26-2005 11:19
Sorry, as this is a bit unrelated, but was wondering...

In the script above from Seagel, he has written...

if (llSubStringIndex(message, "Opacity ";) == 0)

Shouldn't this work just the same?...

if (message == "Opacity";)

Am wondering because I have written several scripts like this, seem to work. Is it written this way to grab the float from the say?

Thanks! Just working on expanding my scripting knowledge today :)
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
09-26-2005 13:53
From: Slayd Lemieux
Sorry, as this is a bit unrelated, but was wondering...

In the script above from Seagel, he has written...

if (llSubStringIndex(message, "Opacity ";) == 0)

Shouldn't this work just the same?...

if (message == "Opacity";)

Am wondering because I have written several scripts like this, seem to work. Is it written this way to grab the float from the say?

Thanks! Just working on expanding my scripting knowledge today :)
Seagel's script expects someone to say "Opacity <some number>", so you can't make a direct comparison as it will fail. So, he checks just the first part of the string, then if that matches, peels off the part of the string that will likely contain the number.

I'd have used:

if (llSubStringIndex(llToLower(message), "opacity ";) == 0)

So upper/lower case would make no difference :)
_____________________
Mod Faulkner
Registered User
Join date: 11 Oct 2005
Posts: 187
Window opacity
11-15-2005 07:14
I know I am probably not posting this correctly by using a reply, but I cannot even figure out how to do an orininal post much less how to deal with window opacity. Please to not kill, just knock me around a bit.

My question is this. I put together the Frank Lloyd Wright House which has a touch control to change the window tent. I would want to modify the script so that instead of just getting more shaded it actuall become black or near black. I have looked at the script for the window and the control, fiddled with some of the values, but have not gotten it right.

Thanks in advance for you patience and help.

MOD
Rodrick Harrington
Registered User
Join date: 9 Jul 2005
Posts: 150
11-15-2005 11:49
I don't know how that script is written, but your best bet is to look through it for all the llSetAlpha() calls. The first number in that call should be between 0.0 and 1.0 with 0 being completely transparent and 1 being fully opaque. Those should be the values you change.

http://secondlife.com/badgeo/wakka.php?wakka=llSetAlpha
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
11-15-2005 14:18
Although actually I've not seen that window, I guess it would change color, too. What about this?
CODE
integer Switch = FALSE;

default
{
touch_start(integer total_number)
{
if(Switch == FALSE)
{
llSetAlpha(1.0, ALL_SIDES); // Opacity
llSetColor(<0.0, 0.0, 0.0>, ALL_SIDES); // Color black
Switch = TRUE;
}
else
{
llSetAlpha(0.1, ALL_SIDES); // Transparency
llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES); // Color white
Switch = FALSE;
}
}
}

p.s. Thank you, Jillian, for answering for me. :)
_____________________
:) Seagel Neville :)
Mod Faulkner
Registered User
Join date: 11 Oct 2005
Posts: 187
Window and Switch Scripts
11-16-2005 05:56
Here are the two scripts (please excuse the formating, it is correct in SL but I have not learned how to do that here yet)

Window Script

// script that changes opacity of object based on external messages

integer gChannel = 5; // communication channel on which we listen for opacity change commands
integer gLastListen; // id of last listen command

default
{
state_entry()
{
gLastListen = llListen(gChannel, "", "", "0";);
}

listen(integer channel, string name, key id, string msg)
{
llListenRemove(gLastListen);

integer nextOpacityLvl = (integer)msg;
nextOpacityLvl += 1;
if (nextOpacityLvl > 3) nextOpacityLvl = 0;
gLastListen = llListen(gChannel, "", "", (string)nextOpacityLvl);

float opacityLvl = (float)msg;
opacityLvl = 1.1 - ((opacityLvl / 3) * 0.9);
llSetAlpha(opacityLvl, ALL_SIDES);
}
}


Switch Script

// script for a switch that controls window opacity
integer gOpacityLevel = 0; // current opacity level of windows
integer gChannel = 5; // channel that controls which windows respond to this switch

default
{
state_entry()
{

}

touch_start(integer num_touchers)
{
gOpacityLevel += 1;
if (gOpacityLevel > 4 )
{
gOpacityLevel = 0;
}
string opacityCmd = "";
opacityCmd = opacityCmd + (string)gOpacityLevel;
llSay(gChannel, opacityCmd);
}
}


Thank to all for your help. Maybe one day I will be able to return the favors.

MOD