Jump to content

llSetLinkAlpha LINK_SET not working in listen event


Calamari
 Share

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

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

Recommended Posts

I'm trying to use llSetLinkAlpha to switch between hiding or showing an object.  When used in a touch event it works fine

integer status = 1;

default
{
    touch_start(integer total_number)
    {
        if(status == 1) 
            {
                llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES);
                status = 2;
            }
            else  
            {
                llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);
                status = 1; 
            }
    }
}

 But When I try it in a listen event, most of the time randomly some of the link # fail to switch when triggered

 

integer listen_handle;
integer channel;
 
alph(float alpha)
{
    llSetLinkAlpha(LINK_SET, alpha, ALL_SIDES);
}
 
default
{
    state_entry()
    {
        channel = 0x80000000 | (integer) ( (string) llGetOwner() );
        listen_handle = llListen(channel, "", "", "");
    }
    listen( integer channel, string name, key id, string msg )
    {
        if(msg == "hold")
        {
            llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES);
        }
        if(msg == "rest")
        {
            llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);
        }
    } 
    on_rez(integer start_param)
    {
        llResetScript();
    } 
    changed(integer change)
    {
        if (change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
}

 

The touch event works all of the time and the listen only part of the time some of the time, and as I'm writing this it getting better, I'm starting to wonder if this is not a script issue but related to my really bad Internet connection?  I've all so tried this with a loop that called each child separately one at time but that too only worked if there was about 0.4 delay between calling each child in the loop, but that ruins the quick hide /show change.

Not sure if this is just a bad connection issue or some thing in the script I've missed, any advice would be greatly appreciated.

Link to comment
Share on other sites

Well, aside from the fact that your second if test should be an else if, the script should run fine.  You might want to be sure that you are always typing the message that you think you are typing -- I have to think about this all the time because I am a lousy typist -- so write

if (llStringTrim(llToLower(msg),STRING_TRIM) == "hold")

for example.  That way, your script will at least ignore accidental white spaces and random capitalization.

Incidentally, you can compress your listen event into something simpler by writing

listen(integer channel, string name, key id, string msg){    msg = llStringTrim(llToLower(msg),STRING_TRIM);    integer idx;    if (~(idx = llListFindList( ["hold","rest"] , [msg] )))    {        llSetLinkAlpha(LINK_SET,(float)idx, ALL_SIDES);    }}

 

 

   

Link to comment
Share on other sites

Thanks Rolig, I think my alpha switching problem is just my bad Internet connection, and by bad I mean it took me 6 hours to log in long enough to be able to reply here with out getting kicked off.


Thanks for the other tips and advice, gives me lots to think about, I like your shorter listen event, I got how all that works except for the bitwise operator ~ Is that toggling the index values from the listFindList?


I like the strong trim tip to, but wish it could just be added as a key on my keyboard or mouse lol

Link to comment
Share on other sites

The bitwise NOT ("~") operator can be somewhat confusing until you realize one important point (well, two actually. LOL).

The result of ~(-1) is 0, all other numbers result in non-zero when the NOT operator is applied to it. Zero is always (within LSL comparisons) interpreted as FALSE and any non-zero value as TRUE.

So, whenever you see a library function that returns a minus one (-1) as one of it's values (usually a "not found" or "out of bounds" condition), you can apply the bitwise NOT operator to its return in a conditional test (such as if() or while()). This is one of the few shortcuts that is both faster and takes less memory than any other approach. 

Link to comment
Share on other sites

if (~(idx = llListFindList( ["hold","rest"] , [msg] )))

is saying (from inside out)

1. Look at the short list ["hold","rest"]

2. Where does the value of [msg] occur within that list?

3. Assign the answer to (2) to the variable idx

4. If the value of idx  is greater than or equal to zero, proceed.

It's that last step that's tricky.  The bitwise operator  ~idx is the same as -(idx + 1) , so if idx is -1, the if test evaluates to zero, which is FALSE.  If idx = 0 or anything greater, the result of the test is TRUE.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3654 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...