Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Making something attached invisible when flying and visible when not?

woofbag Fudo
Registered User
Join date: 3 Aug 2006
Posts: 31
08-29-2007 22:06
I tried altering a script somebody (you know who you are, thanks :D) gave me that activated an animation when flying and turned it off when not to make it so it would make something invisible when flying then visible when not. Here's what I tried:

integer was_flying;

default
{
on_rez(integer param)
{
llResetScript();
}

state_entry()
{
if(llGetAttached())
{
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
}

run_time_permissions(integer perm)
{
was_flying = llGetAgentInfo(llGetOwner()) & AGENT_FLYING;
if(was_flying)
{
llSetAlpha(ALL_SIDES);
}
else
{
llSetAlpha(0,ALL_SIDES);
}
state active;
}
}

state active
{
on_rez(integer param)
{
llResetScript();
}

state_entry()
{
llSetTimerEvent(0.5);
}

timer()
{
integer now_flying = llGetAgentInfo(llGetOwner()) & AGENT_FLYING;
if(was_flying)
{
if(!now_flying)
{
llSetAlpha(ALL_SIDES);
was_flying = now_flying;
}
}
else
{
if(now_flying)
{
llSetAlpha(0,ALL_SIDES);
was_flying = now_flying;
}
}
}
}

Keep in mind I know little to nothing about scripts, so if the problems obvious, or if the whole llSetAlpha method wouldn't work at all anyways, don't hurt me! :p
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
08-30-2007 01:49
If the object in question is made up of more than one prim your setalpha will only work for the prim the script is in.

So you will either have to use link messages and scripts in each prim to toggle visibility or use a for loop to count through the prims in the linkset and use llSetLinkAlpha() to do the work. (This will take some time to get processed though as there is a short penalty delay included. This means the prims won't go all invis or visible at the same tiime but one after the other with about 0.2 seconds delay between each.)
woofbag Fudo
Registered User
Join date: 3 Aug 2006
Posts: 31
08-30-2007 01:55
From: Squirrel Wood
If the object in question is made up of more than one prim your setalpha will only work for the prim the script is in.

So you will either have to use link messages and scripts in each prim to toggle visibility or use a for loop to count through the prims in the linkset and use llSetLinkAlpha() to do the work. (This will take some time to get processed though as there is a short penalty delay included. This means the prims won't go all invis or visible at the same tiime but one after the other with about 0.2 seconds delay between each.)

I was planning on just putting the script in each prim. I really don't know any scripting at all, so I have no idea what you're talking about :p
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
08-30-2007 02:37
From: Squirrel Wood
If the object in question is made up of more than one prim your setalpha will only work for the prim the script is in.

So you will either have to use link messages and scripts in each prim to toggle visibility or use a for loop to count through the prims in the linkset and use llSetLinkAlpha() to do the work. (This will take some time to get processed though as there is a short penalty delay included. This means the prims won't go all invis or visible at the same tiime but one after the other with about 0.2 seconds delay between each.)


That's not true.. I put one script in my multiprim chat keyboard and it sets the entire object alpha.
Darko Lednev
Registered User
Join date: 20 Aug 2007
Posts: 31
08-30-2007 03:39
@ Johan Laurasia:
llSetAlpha doesn't change the alpha of the child prims in a linked set. Just tested it, it didn't work.

@ woofbag Fudo:
Here are two script. One that will go in the root prim and one that will go in all other child prims:

// ROOT PRIM SCRIPT
default
{
state_entry()
{
llSetTimerEvent(3.0);
}

timer()
{
integer info = llGetAgentInfo(llGetOwner());
if (info & AGENT_FLYING)
{
llMessageLinked(LINK_SET, 1, "noalpha", NULL_KEY);
}
else
{
llMessageLinked(LINK_SET, 1, "alpha", NULL_KEY);
}
}

link_message(integer sender_number, integer number, string message, key id)
{
if(message == "noalpha";)
{
llSetAlpha(1.0, ALL_SIDES);
}
else if(message == "alpha";)
{
llSetAlpha(0.1, ALL_SIDES);
}
}
}
// END OF ROOT PRIM SCRIPT

----------------------------------------------------------------

// CHILD PRIM SCRIPT
default
{
state_entry()
{

}

link_message(integer sender_number, integer number, string message, key id)
{
if(message == "noalpha";)
{
llSetAlpha(1.0, ALL_SIDES);
}
else if(message == "alpha";)
{
llSetAlpha(0.1, ALL_SIDES);
}
}
}
// END OF CHILD PRIM SCRIPT

Notice: llSetAlpha doesn't render your object completely invisible because the minimum float value is 0.1 (If you change it to smaller value it will treat it like 0.1. Also if you put negative value it will treat it like positive)! If you want it completely invisible you must use the "completely clear" texture. If you want to do that, contact me in-world, I'll give you one and modify the script to use llSetTexture instead of llSetAlpha.
_____________________
state_entry()
{
llListen(SL Forums, "", NULL_KEY, "";);
}
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
08-30-2007 04:35
Change out the llSetAlpha's with

llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES); and llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES);

If you're making the entire thing invisible, you do not need a script in every prim. Even if you weren't, you could still call llSetLinkAlpha for the prims in question so really no need at all.

llSetLinkAlpha has 0 enforced script delay so even a huge list of them will all execute immediately.
Darko Lednev
Registered User
Join date: 20 Aug 2007
Posts: 31
08-30-2007 04:43
Good one Tiarnalalon...

One script version:

default
{
state_entry()
{
llSetTimerEvent(3.0);
}

timer()
{
if (llGetAgentInfo(llGetOwner()) & AGENT_FLYING)
{
llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);
}
else
{
llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES);
}
}
}
_____________________
state_entry()
{
llListen(SL Forums, "", NULL_KEY, "";);
}
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
08-30-2007 04:45
Ahh thanks, forgot the ALL_SIDES....too early for me to be trying to help people with stuffies lol
woofbag Fudo
Registered User
Join date: 3 Aug 2006
Posts: 31
08-30-2007 12:56
Once again Darko Lednev, you save my bacon! Thanks! :D As for putting this script in what objects, I'm putting this in certain parts of the whole thing to make it look like a certain part of it folds up when on the ground, and folds back out when flying. So couldn't I just unlink what I want to put this script in from the rest of the objects, then highlight all the prims I want this in, and drag the script into one, and they'll all have the script in them? Then I can just link them again?
Darko Lednev
Registered User
Join date: 20 Aug 2007
Posts: 31
08-30-2007 16:41
The last one goes in the root prim. Link all parts and then drag this script in the contents.
_____________________
state_entry()
{
llListen(SL Forums, "", NULL_KEY, "";);
}