Jump to content

looking for a alpha setting controler for many linked prims with just one script


xXCorellXx
 Share

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

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

Recommended Posts

as already in the title am i looking to controle many linked prims with just one script in the root

i have broad idea of what i would need to do that and would just have to repeat the set up of the comands over and over in the script to run it with different kind of child prims like for example child1, child2, child3 and child3

 

default

 

{

state_entry() {

llListen(1,"", NULL_KEY, "");

}

child1()

{

integer i;

for (i=0;i<primCount;i++)

{

if (llGetLinkName(i) == "child1")

 

listen(integer channel, string name, key id, string message) {

if (message == "sheath sword") {

// set the texture

llSetAlpha("1",ALL_SIDES);

if (message == "draw sword") {

// set the texture

llSetAlpha("0.1",ALL_SIDES);

}

}

 

 

}

}

 as matter of fact is my lsl grammar knowledge not even evolved enough to work through
anyone has the patience it takes to sort it out and get it set up for four diferent childprim types?

 

Link to comment
Share on other sites

You have made a valiant start and you have the right idea.  If you want to find and save the link number of the child prim named "child 1", you do indeed need to do something like

for (i=1;i<=llGetNumberOfPrims();i++){    if (llGetLinkName(i) == "child1")    {        gChild1 = i;    }}

 Notice some important differences between what you wrote I what I just put here, though: (1) I am getting the number of links with llGetNumberOfPrims(), (2) I am actually doing something after determining whether a link has the name "child 1", (3) I am putting the value of i into a global integer variable named gChild1 which I will need to declare at the top of the script, (4) I have made sure that all of the { } brackets are paired. EDIT: (5) In a linkset, the root is link #1, not zero, so you have to count from 1 to <= llGetNumberOfPrims().

If you want to do the same for other named links, you can add if tests for them in the same for loop. Notice that the entire for loop has to be in your state_entry event.

Then, when you want to set alpha for a specific prim, you can use llSetLinkAlpha, as in

llSetLinkAlpha(gChild1,1.0,ALL_SIDES);

where you are using that global variable to point to the link you named "child 1".

The only other major suggestion I would make is that you be VERY sure to check that all of your { } brackets are paired and are in the right places. Brackets define the scope of various segments of your script -- states, events, for loops, etc. --- that are treated as unique code blocks.  You need to be sure that you don't mess up where those segments start and stop.

Link to comment
Share on other sites

ok thank you very much let me see if i got that right

default

 

{

state_entry() {

llListen(1,"", NULL_KEY, "");

for (i=0;i<llGetNumberOfPrims();i++)
{
    if (llGetLinkName(i) == "child1")
    {
        gChild1 = i;
    }
}

 

listen(integer channel, string name, key id, string message) {

if (message == "sheath sword") {

llSetLinkAlpha(gChild1,1.0,ALL_SIDES);

if (message == "draw sword") {

llSetLinkAlpha(gChild1,0.1,ALL_SIDES);

}

}

 

}

}

 

and with the same parameters can i now add all the different types of prims i want to cover without adding more scripts to the linkset

 

Link to comment
Share on other sites

Almost.  You forgot the last bit of advice.  You didn't count the brackets to be sure that they are matched properly and in the right places.  Specifically, you opened the state_entry event properly with a bracket, but you never closed it, and you did the same thing with the first for loop in your listen event.  You also have an extra bracket at the very end of the script.  If you try to save that script, you'll get error messages that tell you those things.  You will also get an error message that says your variable called gChild1 is undefined, because you neglected to define it as a global integer at the head of your script.

Formatting is usually easier if you follow standard convention and indent each scope separately.  That way, you can spot unmatched brackets quickly and can tell whether individual commands are in the scope that you think they belong in.

Before you get much farther, I suggest taking time to work through a couple of basic LSL tutorials that will stress these same points and others >>> http://wiki.secondlife.com/wiki/LSL_Tutorial

Link to comment
Share on other sites

ok final attempt

 

 

default

 

{

state_entry() {

llListen(1,"", NULL_KEY, "");

for (i=0;i<llGetNumberOfPrims();i++)

{

if (llGetLinkName(i) == "child1")

{

gChild1 = i;

}

}

 

listen(integer channel, string name, key id, string message) {

if (message == "sheath sword") {

llSetLinkAlpha(gChild1,1.0,ALL_SIDES);

if (message == "draw sword") {

llSetLinkAlpha(gChild1,0.1,ALL_SIDES);

}

}

}

}

}

 

all brackets are matched now and should set propperly

Link to comment
Share on other sites

Hehe... There's never a "final" attempt when you're scripting.  There's a point when you have finally written a script that works, but then you start tweaking, and tweaking never stops. There is no end to the bells and whistles.  :smileywink:

Well, you still don't have the curly brackets properly matched, and you haven't declared the global variable gChild1. (You also never defined the integer variable i, which I didn't notice until just now.)  You did take a good shot at it, though, so compare your most recent script with this one, which works:

integer gChild1;default{	state_entry() {		llListen(1,"", NULL_KEY, "");		integer i;		for (i=1;i<=llGetNumberOfPrims();i++){			if (llGetLinkName(i) == "child1")			{				gChild1 = i;			}		}	}	listen(integer channel, string name, key id, string message) {		if (message == "sheath sword") {			llSetLinkAlpha(gChild1,1.0,ALL_SIDES);		}		if (message == "draw sword") {			llSetLinkAlpha(gChild1,0.1,ALL_SIDES);		}	}}

 Among other things, notice how easy it is to see where each scope begins and ends when you indent properly. 

Even with a short, simple script like this, there are several ways you could have written it, so there's no "right" way.  Just a way that works and makes sense to you.  As you write more complicated scripts, you can also worry about which choices are most efficient, fast, readable, etc.  They will all look different.  If they all accomplish the same thing, though, the one feature they will have in common is logic.  That's the heart of scripting, not the syntax. 

Link to comment
Share on other sites

thank you very much i would have stumbled in the dark forgetting the integer name i tested it and now is there no syntax error anymore lets see if can safe hundreds of scripts to control the linkset

 

integer gsword;

integer gaxe;

integer gdagger;

integer gbow;

integer gclub;

integer gspear;

integer gshield;

default

{

state_entry() {

llListen(1,"", NULL_KEY, "");

integer i;

for (i=1;i<=llGetNumberOfPrims();i++){

if (llGetLinkName(i) == "sword")

{

gsword = i;

}

if (llGetLinkName(i) == "axe")

{

gaxe = i;

}

if (llGetLinkName(i) == "dagger")

{

gdagger = i;

}

if (llGetLinkName(i) == "bow")

{

gbow = i;

}

if (llGetLinkName(i) == "club")

{

gclub = i;

}

if (llGetLinkName(i) == "spear")

{

gspear = i;

}

if (llGetLinkName(i) == "shield")

{

gshield = i;

}

}

}

listen(integer channel, string name, key id, string message) {

if (message == "sheath sword") {

llSetLinkAlpha(gsword,1.0,ALL_SIDES);

}

if (message == "draw sword") {

llSetLinkAlpha(gsword,0.1,ALL_SIDES);

}

if (message == "sheath axe") {

llSetLinkAlpha(gsword,1.0,ALL_SIDES);

}

if (message == "draw axe") {

llSetLinkAlpha(gsword,0.1,ALL_SIDES);

}

if (message == "sheath dagger") {

llSetLinkAlpha(gsword,1.0,ALL_SIDES);

}

if (message == "draw dagger") {

llSetLinkAlpha(gsword,0.1,ALL_SIDES);

}

if (message == "sheath bow") {

llSetLinkAlpha(gsword,1.0,ALL_SIDES);

}

if (message == "draw bow") {

llSetLinkAlpha(gsword,0.1,ALL_SIDES);

}

if (message == "sheath club") {

llSetLinkAlpha(gsword,1.0,ALL_SIDES);

}

if (message == "draw club") {

llSetLinkAlpha(gsword,0.1,ALL_SIDES);

}

if (message == "sheath spear") {

llSetLinkAlpha(gsword,1.0,ALL_SIDES);

}

if (message == "draw spear") {

llSetLinkAlpha(gsword,0.1,ALL_SIDES);

}

if (message == "sheath shield") {

llSetLinkAlpha(gsword,1.0,ALL_SIDES);

}

if (message == "draw shield") {

llSetLinkAlpha(gsword,0.1,ALL_SIDES);

}

}

}

gee everytime when i copy and paste the script are the tabs off again

Link to comment
Share on other sites

OK, you're moving along.  The most obvious problem now is that every single one of the if tests in your listen event calls the same child prim, gsword.  That's not going to help if you are trying to change a different prim.

Once you fix that one, you can improve the efficiency of your script dramatically by changing all but the first if test in both the state_entry event and the listen event to else if.  After all, once your script finds that the result of a test is TRUE, you don't need to have it keep asking whether any of the other tests are also TRUE.

Then you can start thinking of all the other possible ways you might screw up. Did you type the command in the wrong channel, instead of channel 1, as your script expects?  Did you type in upper case by mistake?  Did you misspell the name of one or more of your prims?  Is there a blank somewhere?  There are ways to detect most of those mistakes in the script itself, and you can start building them into the script.  Meanwhile, you  can add temporary llOwnerSay statements (read the wiki to see how) in key places to find out what the script is actually doing instead of what you think it's doing.  This is an interestikng phase of scripting.  You'll probably feel like giving yourself a dope slap more than once.

BTW, you can preserve your indentation by using the code widget as you type here in the forums.  It's that little symbol that looks like a C in a box, right above the edit window.  The symbol to the left of the smiley face. :smileyhappy:

Link to comment
Share on other sites

you can combine some stuff and use a few shortcuts ....

( this supposes that the "root" is not one of the items. )

list main ;integer visible;integer child;default{    state_entry()    {    llListen(1,"",llGetOwner(), "");   // listen to owner only         integer i;          for (i = 2;i < llGetNumberOfPrims()+1; i++) //i=2 root=1,unlinked=0(getlinkName         {  string myName = llGetLinkName(i);            main += myName;                  // add all link names to a list
 llSetLinkAlpha(i,0.0,ALL_SIDES);     //turn all childprims invis } } listen(integer channel, string name, key id, string message) { list recieved = llParseString2List(message,[" "],[""]); // break the msg into 2 parts string command = llList2String(recieved,0); string name = llList2String(recieved,1); if(command == "draw") { visible = 1; } if(command == "sheath") { visible = 0; } if(~llListFindList(main,[name]) ) // if the name is in the childprim list { child = llListFindList(main,[name]) +1 ; //add 1 because setlinkalpha root = 1 } llSetLinkAlpha(child,visible,ALL_SIDES); }}

 

Link to comment
Share on other sites


Xiija wrote:

you can combine some stuff and use a few shortcuts ....

( this supposes that the "root" is not one of the items. )
[ ...]

 

Well, darn.  I was hoping that the OP would work his way up to those complexities himself with a little guidance, but since you offered a shortcut, here's mine............ :smileywink:

//Alpha Weapons --- Rolig Loon --- October 2014// A demo script released for free use, if these top two lines remain intactlist gChildren = ["sword","axe","dagger","club","bow","shield"];list gLinks;default{	state_entry()	{		llListen(1,"",llGetOwner(),"");		integer i=1;		while (i<=llGetNumberOfPrims())		{			integer idx;			//Remove leading and trailing blanks and make name lower case			string PrimName = llStringTrim(llToLower(llGetLinkName(i)),STRING_TRIM);			if (~(idx=llListFindList(gChildren,[PrimName])))			{				gLinks += [PrimName,i];			}			++i;		}		llOwnerSay("OK, here's what gLinks looks like: "+ llList2CSV(gLinks));		//Notice that it contains pairs of PrimNames and link numbers	}	listen(integer channel, string name, key id, string msg)	{		llOwnerSay("I heard " + msg);		msg = llStringTrim(llToLower(msg),STRING_TRIM);		llOwnerSay("This is what it looks like cleaned up: " + msg);		//Separate msg into two parts at the space belween them		list temp = llParseString2List(msg,[" "],[]);		string command = llList2String(temp,0);		llOwnerSay("I heard the command " + command);		integer Action = -1;    //Make the command an integer, with default = -1		if (command == "sheathe")		{			Action = 0;		}		else if (command == "draw")		{			Action = 1;		}		else		{			llOwnerSay("Invalid command.");		}		llOwnerSay("I am interpreting that to mean " +(string)Action);		if (~Action)    //If Action is > -1		{			string link = llList2String(temp,1);			llOwnerSay("Let's find the link number(s) that have that name");			integer i;			while (i< 2*llGetListLength(gLinks))			{				if (link == llList2String(gLinks,i))				{					llOwnerSay("I found one! Applying "+ command + "to link #"+(string)i);					//Multiply 1.0 by Action to get either 0.0 or 1.0					llSetLinkAlpha(llList2Integer(gLinks,i+1),1.0*Action,ALL_SIDES);				}				i = i+2;    //Skip the next entry in gLinks (we're only looking for the names)			}		}	}}

 

 I have loaded this script with many comment statements and a handfull of llOwnerSay commands that the OP can remove once he has learned what he can from them.  I'd suggest making a dummy linkset with lots of prims -- some with duplicated names, some in upper case, ... -- to play with it and see how it works.  As I always tell a client, "See if you can break it.  If not, then you can pay me." :smileylol:

Notice that this version does not care how many child prims may have the same name.  It saves them all.  Therefore, if you have an axe made of several prims the whole thing will go transparent or visible.  Also, notice that it doesn't make any difference whether the root is one of the items.  As you work through this script, you'll see that it has safeguards to keep anyone but the owner from sending messages to it, and for recognizing when a command is not typed in lower case or has unnecessary leading or trailing spaces.  Or is an invalid command.

Remember that I said earlier that no script is ever "finished".  There's always room for tweaking.  As an exercise for the OP, see if you can figure out how to make all of the weapons vanish (or appear) at once.  How would you allow a trusted friend to send a command?  How would you play a sound when drawing or sheathing a sword?  How would you trigger an animation?

EDIT:  Notice, BTW, that this is a wasteful way to script the solution if ALL of the child prims are weapons of one sort or another.  After all, if that's the case, there's no point in creating the list gLinks.  So, another challenge .....  how would you rewrite the script without creating and reading from gLinks?

Link to comment
Share on other sites

this set up looks smooth to me i apreciate that it doesnt mind multiple items being called the same which is indeed very helpfull

 

to get the logic right behind it the linked prims are listed as integer with names and the later defined comands in combination with integer names of the prims trigger events just random comands do not and will be a failur

so what if i combine a comand and then all interger names as oen word like draw swordaxedaggerbowclubshield ?

just imagine me taking out my swiss army knife you know lol

Link to comment
Share on other sites

Hehe ...  I told you the tweaking never ends.  I wasn't actually going to give you a script like that, because that's not the purpose of this forum.  You'll learn a lot better if you build your own script slowly and carefully, so that you understand the logic all along the way. Now that you have my script and Xiija's, I suggest that you spend time taking them both apart, comparing them to see what they do and why we have made the choice we have made, and then doing some gentle tweaks of your own.  You have two working scripts.  See what you can do to make them your own.  If they break, you always have working versions you can fall back on.

Rather than answer your question directly, let me rephrase it.  Suppose you want to combine two or more weapon names into a command string. How will you know where one stops and the next one begins? Will it make any difference what order the names are in? Are there LSL functions in the two scripts you have that might help?  There's no unique answer.  Just find a solution that works.

Link to comment
Share on other sites

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