Jump to content

Listener Script that makes one link visible and all others not invisible


TheSarali
 Share

You are about to reply to a thread that has been inactive for 2893 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

So... I'm pretty sure I'm missing something basic here, but my brain is super tired and things aren't working right, and I'm super frustrated, so if anybody with fresh eyes could look this over and tell me why it's failing I'd really appreciate it.

 

What this is supposed to do is, when a button is clicked on the HUD, it takes the name of the button prim and sends it to the listening script in an object.  That, I think, seems to work fine.

The script in the object then is supposed to take that name, and is supposed to make any link in that object with the name visible, while making all other objects invisible.

 

Eventually I'd like to make it so that it makes just one face of one particular linked prim invisible in the object by pushing a button in the HUD.  But I figured I'd start out with baby steps.  This is the code, so... yeah.  I'm sure there's a simple mistake or two in here that's screwing it up, and any help you could offer would be much appreciated.  Thank you!

HUD Script:

integer link_num;
string prim_name;

default {
    touch_start( integer n ) {
        link_num = llDetectedLinkNumber(0);
        prim_name= llGetLinkName(link_num);
        
        if(link_num == 1){
            //This is so that clicking the root prim does nothing.  There's robably a more elegant way to do this.
        }
        else if(prim_name == "Minimize"){
            //This is just an example for in the future, since a Minimize and Maximize button will probably be handy.
        }
        else{ //This is for all other buttons, since I figure most of the buttons will be for changing which part shows
            llRegionSay(-75260,prim_name);
        }
    }
}

Object Script:

integer face_num;
string prim_name;

integer link_num(string hud_prim_name)  //function to get link number based on the hud_prim_name string retrieved from the listener script
        {
            integer primCount = llGetNumberOfPrims();
            integer i;
            for (i=0; i<primCount+1;i++)
            {
                if (llGetLinkName(i)==hud_prim_name) return i;
            }
            return FALSE;
        }

default
{
    state_entry()
    {
        llListen(-75260, "", llGetOwner(), ""); //target only the owner's chat on channel -75260
    }
 
    listen(integer channel, string name, key id, string hud_prim_name)
    {
        llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES);
        llSetLinkAlpha(link_num, 1.0, ALL_SIDES);  //calls the link_num function using the hud_prim_name string to get link ID
    }
}
Link to comment
Share on other sites

there are 2 things wrong that I can spot right away. first. llListen is set to listen only to the owner, it will not hear objects, even if they are owned by the same owner. you would filter the listen (in case objects from other owners just happen to use the same channel) for objects owned by the owner. Another alternative would be to use a dialog rather than a hud, then it would only need to listen to the owner.

for the hud button method, you would leave the listen open by leaving all but the channel field blank:

state_entry()    {        llListen(-75260, "", "", ""); //listen for anything on that channel    }

then in the listen event you would filter out using llGetOwnerKey and llGetOwner:

listen(integer channel, string name, key id, string hud_prim_name){if(llGetOwner() == llGetOwnerKey(id))//checks to makes sure the speaking object (or avatar) is owned by the same owner{insert other code.............}}

 

the second thing is in llSetLinkAlpha(link_num....

in 

integer link_num(string hud_prim_name)

it wants you to feed it a string in the parantheses, but in llSetLinkAlpha(link_num, you're not doing that. it should be:

 llSetLinkAlpha(link_num(hud_prim_name), 1.0, ALL_SIDES);

 

Link to comment
Share on other sites

Oh, that explains a ton.  Thank you!  I'm just heading to bed, but I'll try those tomorrow.  I tried to filter to the owner right at the beginning to make the script as light as possible, but that's close enough to the beginning that it'll have to do.  Much appreciated.

 

Assuming this works I'll then have to move on to implementing it on to faces, as well as objects.  But that's pretty much the same idea, just... nested, I think.  I'll get to that once I get this working.  Thank you.

Link to comment
Share on other sites

No problem. Another thing is, depending on what you're using it for. The way you have the for-loop set up, it will only find the first link with the same name. If you have multiple links with the same name that you intend to hide/show at the same time, you would want to move

llSetLinkAlpha(link_num(hud_prim_name), 1.0, ALL_SIDES);

Into the loop

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2893 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...