Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Keeping things unseen

Aphanteus Iuga
Registered User
Join date: 18 May 2007
Posts: 12
02-16-2008 05:49
First, I am a complete idiot when it come to LSL. I haven't learned anything by reading. Instead I have learned by "seeing" what various scripts do and attempting to alter my scripts to do the same thing.

Presently I am working on a pair of sunglasses that can be raised up on the head. That works fine. But when I state the command to change the texture of the lens from clear to mirrored or visa versa, all four lens show, both the visible and the invisible.

Here is the script. Does anyone have any suggestions?

default
{
state_entry() {
llListen(600,"", NULL_KEY, "";);
}

listen(integer channel, string name, key id, string message) {
if (id != llGetOwner())
return;
if (message == "clear";)
{
llSetTexture("white",ALL_SIDES);//the texture shown in the default state is "window".
llSetAlpha(1.0,ALL_SIDES);//1.0 shows all of a texture, 0.0 shows none
llScaleTexture(1,1, ALL_SIDES);//adjusts texture scale if needed.
}
else if (message == "mirror";)
{
llSetTexture("silver",ALL_SIDES);
llSetAlpha(1.0,ALL_SIDES);
llScaleTexture(1,1, ALL_SIDES);
state default;
}
}
}
Sho Iuga
Registered User
Join date: 6 Jun 2007
Posts: 35
02-16-2008 06:39
The problem you have is you put in a llSetAlpha function call in a place where you only want to change the texture. Try to just remove the llSetAlpha lines from the code you have shown us.
Aphanteus Iuga
Registered User
Join date: 18 May 2007
Posts: 12
02-16-2008 07:00
That was it...thank you! Can you possibly explain what that was doing and what its purpose is?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-16-2008 07:59
am I to understand that this script is in 4 diferent prims, presumably 2 for each style?

you should only need 2 prims, and really only should have one script that listens, then uses a link message to tell the others what to do.

I don't see you turning off the alpha anywhere, so of course all prims with this script would show up, since the script turns it on every time it gets a change call.

you could also lose the scale texture calls, or if you intend to configure them (and the alpha) on an individual basis, you could use llSetPrimitiveParams to do the same things all together at once

I'm also unsure of why you are restarting the default state, in the second case, since the effect is only to restart the already active listen. this can be removed as well.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Sho Iuga
Registered User
Join date: 6 Jun 2007
Posts: 35
02-16-2008 08:01
llSetAlpha sets the opcity of the specified side of the prim it is in.

llSetAlpha(1.0, ALL_SIDES) makes all sides of a prim fully opaque ( though if the texture itself is transparent it will still be transparent)
llSetAlpha(0.0,ALL_SIDES) make all sides of the prim fully transparent.
llSetAlpha(0.5, 1) makes side 1 half transparent.

The llSetAlpha you deleted from your script were in a section, where you only wanted to change the texture, not the opacity. Your commands "mirror" and "clear" are not supposed to change the opacity of your lenses, so the llSetAlpha function call should not have been there in the first place.
Sho Iuga
Registered User
Join date: 6 Jun 2007
Posts: 35
02-16-2008 08:35
I guess Void Singer wants the scripts for your glases look like that. This has only one listener, and the commands are given to the other prims via llMessageLinked function call:


//Script in root prim
default
{
state_entry()
{
llListen(600, "", llGetOwner(), "";);
}
listen(integer channel, string name, key id, string message)
{
llMessageLinked(LINK_SET, 0, message, "";);
//this transmits the command to all linked prims
//this way we need only one of those lag creating listeners
//for the whole object
//the residents are thankfull, that you try to avoid lag creating scripts
}
changed(integer change)
{
if(change & CHANGED_OWNER) llResetScript();
//we need to set the listener again as the script only listens to owner
}
}



//script for the prims in the head part of your glases, not the lenses
default
{
link_message(integer sender_number, integer number, string message, key id)
{
if("head" == message)
{
llSetAlpha(1.0, ALL_SIDES);
//set headpart opaque, glsses are in head position after all
}
if("nose" == message)
{
llSetAlpha(0.0, ALL_SIDES); //set headpart transparent
}
}
}



//script for the prims in the lenses of your glases, head position
default
{
link_message(integer sender_number, integer number, string message, key id)
{
if("mirror" == message)
{
llSetTexture("silver",ALL_SIDES); //set texture for mirror command
}
if("clear" == message)
{
llSetTexture("white",ALL_SIDES); //set texture for clear command
}
if("head" == message)
{
llSetAlpha(1.0, ALL_SIDES); //set headpart opaque
}
if("nose" == message)
{
llSetAlpha(0.0, ALL_SIDES); //set headpart transparent
}
}
}



//script for the prims in the nose part of your glases, not the lenses
default
{
link_message(integer sender_number, integer number, string message, key id)
{
if("head" == message)
{
llSetAlpha(0.0, ALL_SIDES); //set nose transparent
}
if("nose" == message)
{
llSetAlpha(1.0, ALL_SIDES); //set nose opaque
}
}
}



//script for nosepartlenses
//well, I guess you can do that yourself
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-16-2008 11:26
Side note: if you want to simply move something like sunglasses to another position on the same attach point, you don't have to do the transparency trick. You can use llSetPrimitiveParams() to actually move the attachment.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-16-2008 11:46
that's much more complicated than what I had in mind.... but then I was assuming you rotated the glasses for each position, rather than having invisible prims for each mode (on head, on nose).

as regards just the texture changing, you could actually do it with one listen, in one single script, for all the lenses, using llSetLinkPrimitiveParams. or if simultaneous change is imjportant, the same script in all four lenses, activated on a link message, with only one modified to use a listen and trigger the message when it hears it's command.

now that I understand you're using the alpha to hide parts of the object (the different position) it's easy to see why it was breaking... you were telling the hidden lenses to show themselves with the set alpha call.

side note:
in the edit window, the alpha is controlled as a percentage of transparency
in lsl the alpha is controlled as a percentage of opacity (the opposite of the edit window)

most references to alpha are given in terms of transparency... because without the alpha, there is no transparency.... LSL of course has to be a pain in the rear and take the literalist view, and give you a percentage of opacity, as in "what percentage is the image visible". This is a case of being technically correct with no benefit, over following tradition and standard practice. =/
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
02-20-2008 00:47
And another note - don't use these shades in windlight or you'll see all the lenses yet again and it will drive you crazy.