There we go again, you might think, but no, this time Five stays practical.
Five wants to show you something. A handler which might be handy when working with linked objects. A linked object, when scripted, mainly functions from its root object, sending messages to the links, or receiving info from these links. The linked objects have numbers, depending on which order you follow linking them together.
If you change the order, the numbers are changed. This is terrible! For instance making a HUD with digits, you have to be careful to take the same order, and when you decide to link something within this order, you can change the whole script! This is because although the function llGetLinkName(integer linknum) exists, there is only llGetLinkNumber() in the link itself! Not something like llName2LinkNumber(string name)!
And this is quite needed, sending commands to the links from the root, with llMessageLinked().
So Five proposes a small function, see how it works:
This is all taking place in your root script, please give a name to every link, for instance (for the digital clock) digit1, digit2, digit3, digit4, digit5, digit6, etcetera.
Than at the top of your script you declare a list, linkNameList. Then you make a function, going through the whole list of linked objects, and noting the names of the objects. It is as simple as that.
list linkNameList = [ ];
///////////////////////////////////////////////////////////////////////
//getting linknumbers from link names this in state_entry handler
getLinkNameNumberList()
{
integer x;
//x=0 is taken by the root returns 00000000-0000-0000-0000-000000000000
//so we have to go to llGetNumberOfPrims() + 1, to get all the linked objects
for (x=0;x<llGetNumberOfPrims() + 1;x++)
linkNameList +=[x,llGetLinkName(x)];
//these last lines can even be left out, just for checking
integer check = 0;//if check = 1 this gives list of numbers and names
if (check==1)
for (x=0;x<llGetListLength(linkNameList);x+=2)
llSay(0, (string)(x / 2) + " " + llList2String(linkNameList,x) + " " + llList2String(linkNameList,x+1));
}
Ok, then all we need is a small function to be used in the rest of the script, simply replacing the name of the object by the number. Put this function also above the default
// linkName -> linkNumber
integer name2LNum(string linkName)
{
integer x;
for (x=0;x<llGetListLength(linkNameList);x+=2)
if ( linkName == llList2String(linkNameList,x+1) ) return x / 2; //the 2 is because of the ‘strided’ list
return 0; //returning 0 means an error: name not found
}
At the state_entry of the default, we simply call the preparation….
default
{
state_entry()
{
getLinkNameNumberList();//this prepares the list of names and linknumber
//etc….
And now somewhere else in the script, instead of
llMessageLinked( 12 , my1000, "", NULL_KEY); //where 12 is the number of the link
and you can edit and renumber the 12 every time the link order is changed, you use the nice function, just by the putting in the name of the linked object you want to send a message
llMessageLinked( name2LNum("digit4") , days, "", NULL_KEY);
llMessageLinked( name2LNum("digit3") , hours , "", NULL_KEY);
llMessageLinked( name2LNum("digit2") , minutes , "", NULL_KEY);
llMessageLinked( name2LNum("digit1") , seconds, "", NULL_KEY);
So regardless of the linkorder or the complexity of the linked prim, the script will find your digit without a problem!
Aucun commentaire:
Enregistrer un commentaire