Jump to content

Scripting novice needs help with executing a loop


Lilah Munster
 Share

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

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

Recommended Posts

Hello :-)

I am trying to get a script working to either hide or show parts of a linkset by chat command.  I am trying to use a loop to make things easier on myself, but obviously, I don't completely understand what I am doing yet.  (But hey, at least I didn't launch the item to 4,096m this time!)  The script is below - it saves and compiles, then fails silently.

 

key show_rings;
key hide_rings;
key show_nails;
key hide_nails;
integer i;


default
{
    state_entry()
    {
        llListen(42,"",llGetOwner(),"");

    }
    
    on_rez(integer param)
    {
        llResetScript();
    }
    
    listen(integer c, string n, key k, string m)
    

    {
        if (m="show_rings");
            do llSetAlpha (1.0, ALL_SIDES);
            while (llGetLinkName(i) =="ring");

        if (m="hide_rings");
            do llSetAlpha (0.0, ALL_SIDES);
            while (llGetLinkName(i) =="ring");

        if (m="show_nails");
            do llSetAlpha (1.0, ALL_SIDES);
            while (llGetLinkName(i) =="nail");

        if (m="hide_nails");
            do llSetAlpha (1.0, ALL_SIDES);
            while (llGetLinkName(i) =="nail");
    }
}

 

I am missing something, but I can't see what.  Thanks in advance for any guidance in the right direction :-)

Link to comment
Share on other sites

        if (m="show_rings");

do llSetAlpha (1.0, ALL_SIDES);

while (llGetLinkName(i) =="ring");

 



This should be:

if (m == "show rings")

{

i = 1 ;// the first link

while (llGetLinkName(i)=="ring")

{

llSetLinkAlpha(i, 1.0, ALL_SIDES);

i += 1;

}

}

}

 

Your errors are numerous.  I'm saying this to be a jerk, but you should reaquaint yourself with C if you are going to script, as LSL is a cross between C and Java. 

= is an assignment; == is a comparison.

having a ; after a comparison test will mean there is no code the comparison runs if true.

do loops don't work the way you think - they always execute at least once and then check to see if they should run again.

If you want to test first then run in a loop, you have a while loop.

 

A good resource for LSL and examples of it can be found here.  http://lslwiki.net/lslwiki/wakka.php?wakka=HomePage  There is also a LL webpage for the scripting language, but I find this one easier to use.  

Good luck to you.  If it helps, just as with any other coding exercise the learning curve is steepist when you are just starting out.  Don't let that discourage you.  Look at the examples given and learn from them, and you'll be over the hump in no time.

 

 

 

 

Link to comment
Share on other sites

Thank you for your advice, however there is no "reacquainting" myself with C, because I have never used C.  Or Java, for that matter.

Your example fails silently, as well.  I know how to do this using llSetLinkPrimitiveParams, but I was hoping to do something more streamlined.

Link to comment
Share on other sites

I do this a bit differently.   Rather than check the link names each time I call the function, I write a user function, on these lines, which I then call in state_entry(), on_rez(),  in the changed event and anywhere else that seems sensible:

list rings;list nails;find_prims(){	integer max = llGetNumberOfPrims()+1;//link numbers start at 1 in linksets, not at 0	while(max--){		string s = (string)llGetLinkPrimitiveParams(max,[PRIM_NAME]);		if(s=="ring"){			rings+=[max];		}		else if(s=="nail"){			nails+=[max];		}	}}

 then, in the listen event, I simply run through the list, like this

listen(integer channel, string name, key id, string message)	{		list l;		float alpha;				integer n = llSubStringIndex(message,"_");		if(llGetSubString(message,0,n=="show"){			alpha=1.0;		}		else if(llGetSubString(message,0,n=="hide"){			alpha=0.0;		}		if(llGetSubString(message,n+1,-1)=="rings"){			l=rings;		}		else if (llGetSubString(message,n+1,-1)=="nails"){			l=nails;		}		n=llGetListLength(l);		while(n--){			llSetLinkAlpha(llList2Integer(l,n),alpha,ALL_SIDES);		} 	}

 

Link to comment
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...