Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: ~How to use llLinkMessage for advanced stuff~

Shippou Oud
The Fox Within
Join date: 11 Jul 2005
Posts: 141
12-24-2006 14:18
I've gotten into a debate on this subject, and found a lot of folks do not know you can use LinkMessage to manipulate individual prims in a linked set. If anyone out there knows an easier way of obtaining the link numbers of each individual prim, let me know.
Here is a sample of LinkColor.
CODE

llSetLinkColor(19,<9,.1,.5>,ALL_SIDES);

Now what does this mean, and do?
The first number ( 19 ) is the prim that is going to be affected, the second set of numbers ( <9,.1,.5> ) is the color, and the "ALL_SIDES" means...well, it affects all the sides of the prim.

Now this seems simple right? One problem, what prim is #19, and how did I find it out?
Once you link objects together, they get an unchanging Link Number assigned to them, the problem is how to get that number out of each prim.
Put this script in EACH prim, get out a pen and paper, clicking on each prim, will reveal it's individual number (it will NOT work if you simply stick it in the root prim, and trying to click on the individual prims)
CODE

default
{
touch_start(integer total_number)
{
integer ww1;
ww1 = llGetLinkNumber();
llInstantMessage(llGetOwner(), "This prim's link # is; " + (string) ww1");
}
}


Remember to delete the script after it's usefulness is done.

Now on for LinkMessage.

CODE

llMessageLinked(22, 0, "cc", "NULL_KEY");

and
CODE

link_message(integer int,integer num,string str,key id)
{
if (str == "cc")
{
v1 = llFrand(1.0);
v2 = llFrand(1.0);
v3 = llFrand(1.0);
c1 = < v1,v2,v3 >;
llSetColor (c1,ALL_SIDES);
}
}

The first one sends out a message to prim #22, the message is "cc".
The second one listens for a message , and if the message is "cc" is generates a random color.

This is how I know how to manipulate individual prims, with Link Message, as I said before, if anyone knows an easier way with out creating massive lag, let me know.
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
12-24-2006 20:51
/15/51/156701/1.html
_____________________
i've got nothing. ;)
Adept Pascal
Elite, get over it.
Join date: 25 Jun 2005
Posts: 26
12-25-2006 02:25
From: Shippou Oud
If anyone out there knows an easier way of obtaining the link numbers of each individual prim, let me know.


string llGetLinkName(integer linkNum) should be of use in this particular example.
http://www.lslwiki.com/lslwiki/wakka.php?wakka=llGetLinkName

You can name the prim you're after then use this function to get the link number by name.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
12-25-2006 02:29
You can also simply set the link number when linking, by selecting all the prims in reverse order. The last prim you select before linking will be 1, the second-last 2, the third-last 3 etc. If you're making a display system, say, which needs to linkmessage multiple component prims, that's easier and faster in practice than having to fill in a list of link numbers in your script.
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!

http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal

http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names
Alexis Starbrook
CEO - Alexis Digital
Join date: 7 Dec 2006
Posts: 135
12-25-2006 03:49
Well, I jsut started in LScript about a week ago, but I am lucky to have over 30 years programming in Basic and PERL.

I got a bit annoyed trying to figure out how to do messages to just one specific prim so I did them to all in the Link Set

Using the LINK_SET option I send out an Identifier
IE:
llMessageLinked(LINK_SET, 0, "Command_String", NULL_KEY);


In the prim I want it to do stuff in I just look for the 'Command_String" to appear on the channel

link_message(integer sender_num, integer num, string msg, key id)
{
// Question MArk
if (msg == "Command_String";) {
llSetTexture("question",ALL_SIDES);
}
}

The above sets a texture on a sepeate prim in the link group from another prim.
Many be a flippy way to do stuff, but whatever works is fine with me..
_____________________
Dalien Talbot
Registered User
Join date: 17 Aug 2006
Posts: 1
Finding out which prim is which link
12-25-2006 05:03
According to my experiments, actually the link# is the reverse order in which the prims are selected while link them together in the editor.

So, if you have 3 prims, the first one you select gets #3, the second #2, the third one will be #1 (and hence the root prim).
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
12-25-2006 09:20
I second the use of prim naming and storing link numbers in organized lists via the use of llGetLinkName(). It's about the best way I have found to manage individual prims in a linkset, since it isn't always possible to link prims in any arbitrary order (some complex builds have lots of prims, some mostly or totally inside other prims) because trying to click on them to set their order is a nightmare.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-25-2006 09:44
From: Shippou Oud

Put this script in EACH prim, get out a pen and paper, clicking on each prim, will reveal it's individual number (it will NOT work if you simply stick it in the root prim, and trying to click on the individual prims)

Actually you don't have to jump through all of these hoops Shippou. Instead of using llGetLinkNumber, use llDetectedLinkNumber.
Just place this script in the root prim and touch any of the prim to see it's link number. No need to place a script in each prim:
CODE
default{
touch_start(integer num_detected) {
integer link = llDetectedLinkNumber(0);
llOwnerSay("This is link #" + (string)link);
}
}

llDetectedLinkNumber works great in HUDs. You can just use one script and each different button touched can do something different in that script.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-26-2006 09:15
From: Shippou Oud

CODE

llMessageLinked(22, 0, "cc", "NULL_KEY");

and
CODE

link_message(integer int,integer num,string str,key id)
{
if (str == "cc")
{
v1 = llFrand(1.0);
v2 = llFrand(1.0);
v3 = llFrand(1.0);
c1 = < v1,v2,v3 >;
llSetColor (c1,ALL_SIDES);
}
}

The first one sends out a message to prim #22, the message is "cc".
The second one listens for a message , and if the message is "cc" is generates a random color.

This is how I know how to manipulate individual prims, with Link Message, as I said before, if anyone knows an easier way with out creating massive lag, let me know.

Now for this part instead of sending link messages and having to have a script in both the root prim and in this case link#22, all you have to do is have this in the root prim:

CODE

vector color;
default{
touch_start(integer num_detected) {
color.x = llFrand(1.0);
color.y = llFrand(1.0);
color.z = llFrand(1.0);
llSetLinkColor(22, color, ALL_SIDES);
}
}

In that case touching the root prim will change the color of link #22. If you want to change the color of link #22 by touch link #22 without having a script in it then you can put this in the root prim instead:
CODE

vector color;
default{
touch_start(integer num_detected) {
integer link = llDetectedLinkNumber(0);
if(link == 22){
color.x = llFrand(1.0);
color.y = llFrand(1.0);
color.z = llFrand(1.0);
llSetLinkColor(22, color, ALL_SIDES);
}
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-26-2006 09:38
From: Alexis Starbrook
Well, I jsut started in LScript about a week ago, but I am lucky to have over 30 years programming in Basic and PERL.

I got a bit annoyed trying to figure out how to do messages to just one specific prim so I did them to all in the Link Set

Using the LINK_SET option I send out an Identifier
IE:
llMessageLinked(LINK_SET, 0, "Command_String", NULL_KEY);


In the prim I want it to do stuff in I just look for the 'Command_String" to appear on the channel

link_message(integer sender_num, integer num, string msg, key id)
{
// Question MArk
if (msg == "Command_String";) {
llSetTexture("question",ALL_SIDES);
}
}

The above sets a texture on a sepeate prim in the link group from another prim.
Many be a flippy way to do stuff, but whatever works is fine with me..


Unless I need to exlicitly pass data to a child to work on , such as a texture ID or some encoded information, I prefer to define a set of constants which can be passed as the second parameter to the llMessageLinked Function. A numeric compare is far quicker than a string compare.

CODE
llMessageLinked(LINK_SET, COMMAND_XXX, "Command_parameters", NULL_KEY); 


CODE


link_message(integer sender_num, integer num, string msg, key id)
{
if (COMMAND_XXX == num) ProcessCommandXXX(msg);
else if (COMMAND_YYY == num) ProcessCommandYYY(msg);
}


You could also use the same idea with the num value built from Bit parameters.
Gearsawe Stonecutter
Over there
Join date: 14 Sep 2005
Posts: 614
12-27-2006 20:31
Also note not to over use link message. when you are just sending a single command to a root prims. Such as a HUD setup where you have many buttons that may send a single command to the root prim. so name the buttons "up", "down", "left", "right"

CODE

//...
touch_start(integer total_number)
{
command = llCSV2List(llGetLinkName(llDetectedLinkNumber(total_number - 1);));
if (command == "up")
{
//CODE
}
else if (command == "down")
{
//CODE
}
else if (command == "left")
{
//CODE
}
else if (command == "right")
{
//CODE
}
}
//...More Event
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-28-2006 02:02
Expanding on what Gearsawe posted, this is another situation where numeric constants work better than using the prim names. Yes its a bit more fiddly, you link and then find out what the linknumbers are to make the constants , but its still more efficient than string comparissons in the long run.

CODE

//...
touch_start(integer total_number)
{
integer command = llDetectedLinkNumber(0);
if (MOVE_UP == command)
{
//CODE
}
else if (MOVE_DOWN == command)
{
//CODE
}
else if (MOVE_LEFT == command)
{
//CODE
}
else if (MOVE_RIGHT == command)
{
//CODE
}
}
//...More Event
Gearsawe Stonecutter
Over there
Join date: 14 Sep 2005
Posts: 614
12-28-2006 14:00
Yes that is ture Newgate, numbers are much faster to compare.
In your state entry use this to get your Constants

CODE

state_entry()
{
integer i = 1;
integer num_links = llGetNumberOfPrims();
string link_name;
while (i <= num_links)
{
link_name = llGetLinkName(i);
if (link_name == "up") MOVE_UP = i;
else if (link_name == "down") MOVE_DOWN = i;
else if (link_name == "left") MOVE_LEFT = i;
else if (link_name == "right") MOVE_RIGHT = i;
i++;
}
}

Very useful if you are editting the Set of prims adding some and removing others. Just reset the script again and you're good to go. Don;t have to worry about putting scripts in the prims to find out what link they are. Thanks to Kanker Greenacre for showing me this. http://lslwiki.com/lslwiki/wakka.php?wakka=LibraryLinkNumsScript
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-28-2006 14:49
I do something pretty similar but with an external script that just dumps a set of constants out for me.
JoeTheCatboy Freelunch
Registered User
Join date: 14 Jun 2006
Posts: 42
12-29-2006 10:51
My understanding is that llSetLinkColor or whatever is faster than llMessageLinked. That way you can have a script inside the specific prim that checks to see if its color is changed, and then act on it. An easy way to make it unnoticeable is to give it a transparent texture.
Ingwa Tuni
Registered User
Join date: 6 Nov 2006
Posts: 1
12-30-2006 07:03
Why not use the description field for the linked items and in the linked object have this:

if(llGetObjectDesc()==(string)num)

That then checks the number you have assigned in the second attribute of your linked message, and then if they are equal to each other do something. Makes putting the same script in many linked items easier to update too.