Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Linkset question

Cloud Renierd
Registered User
Join date: 6 Feb 2009
Posts: 6
03-17-2009 16:01
Is it possible to detect which prim in a linkset the user has clicked on? To create an example, say I've got several prims in close proximity and would like to be able to have the user click on one and change its (and only its) color.

Just learning LSL. Thanks for any assistance in the process.
Cypher Ragu
[Mad Scientist]
Join date: 6 Jul 2008
Posts: 174
03-17-2009 16:10
Put something like this script in the child prim:


//Begin Script

vector color = <0.0, 1.0, 0.0>; // Green
default
{
touch_start(integer num_detected) // Someone has clicked the prim
{
llSetColor(color, ALL_SIDES); //Sets the color of the prim
}
}

//End Script




As long as that's in the child prim, it should act like a seperate object.
_____________________
Life is a highway... And I just missed my exit.
Cloud Renierd
Registered User
Join date: 6 Feb 2009
Posts: 6
Thanks :)
03-17-2009 17:00
Thank you Cypher.

I appreciate the help.

Another question.

It looks like llMessageLinked() and link_message can be used to communicate between scripts in an object. So, since linksets allow several objects to behave as one object, does the concept apply to the scripts in the different prims? Is one script in prim1 able to communicate to a script in prim2 via the linkset construct? I'll be testing it in the meantime, but guidance would be just great.

Edit: I took out a part that stated incorrect information I learned wasn't true for future readers trying to learn from the forums.
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
03-17-2009 17:02
There is no need to put a script into every child prim.

Use the llDetectedLinkNumber() function within a single root-prim script. You can detect the individual child prim link numbers, and even the individual face of each linked prim.

The following script should do it:

vector COLOR = <1.0, 0.0, 0.0>; // red

default
{
touch_start(integer num)
{
llSetLinkColor(llDetectedLinkNumber(0), COLOR, ALL_SIDES);
}
}

To affect only the face touched, use this function:
llSetLinkColor(llDetectedLinkNumber(0), COLOR, llDetectedTouchFace(0));
Cloud Renierd
Registered User
Join date: 6 Feb 2009
Posts: 6
Very helpful
03-17-2009 17:14
@DoteDote

That was very helpful.

So, I was actually wrong in saying that touching a child prim doesn't cause the root prim's script to run. It actually must.

Thanks guys.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
03-17-2009 17:31
From: Cloud Renierd
@DoteDote

That was very helpful.

So, I was actually wrong in saying that touching a child prim doesn't cause the root prim's script to run. It actually must.

Thanks guys.

The only time touching a child prim does not fire the root prim script is if the child prim has a script with a touch event in it.

EDIT: To elucidate some. You can use this to your advantage. If you have a prim or panel you do not want to fire a touch event then you can put a script in it with an empty touch event.

Back to DoteDote's script. As your hud or linkset becomes more complicated and has more parts you can also give each prim a unique name. During the start event you can associate the link number with the unique names. Just ask here whenever you are ready to take the next step in this direction.
_____________________
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
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
03-18-2009 04:24
I'm not sure if it is actually "proper" or not, but I create a lot of linked objects with multiple events depending on which prim's been touched, and I've found that for me, it helps to use a non-touch root prim, even if that prim gets 86'd toward the end of development.
Cloud Renierd
Registered User
Join date: 6 Feb 2009
Posts: 6
03-18-2009 20:04
From: Jesse Barnett
The only time touching a child prim does not fire the root prim script is if the child prim has a script with a touch event in it.

EDIT: To elucidate some. You can use this to your advantage. If you have a prim or panel you do not want to fire a touch event then you can put a script in it with an empty touch event.

Back to DoteDote's script. As your hud or linkset becomes more complicated and has more parts you can also give each prim a unique name. During the start event you can associate the link number with the unique names. Just ask here whenever you are ready to take the next step in this direction.


I see a name field when I rez objects that I can use. There's even a function, llGetLinkName, to get the name. But how to associate it with llDetectedLinkNumber(0)?

Edit: Another question for you guys. If I have a root prim with a primary script in it, and the child prims are using it for their purposes, how are state changes handled? Do each of the child prims keep a log of their own state in the script, or is it really best to keep an instance of the script changing scripts in each of the child prims after all? I saw good success with the root prim script for the children - and it appears that you have to do that if you use linked messages a lot - but I ran into bugs when I wanted to have the children change their states independently. There's something I don't understand yet.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-18-2009 21:00
prims are numbered in the reverse order they are linked via edit (the last prim added will be the root)

added prims (via llCreateLink) are inserted in the numbering order after the root prim, if a whole object (multiple prims) is added, those prims retain their order in the new insertion

avatars seated on an object also count as a numbered prim, their number is added as the last in the sequence. additional seated avatars will have sequentially higher numbers


when a link_message is received, the name of the sending prim can be grabbed, by using llGetLinkName( sender_num ), and then based on the touched prims name do different actions. this method doesn't require a script in the touched prim if used with the touch event in the root (replace sender_num with llDetectedLinkNumber)

alternatively you can do this the other way around, and check the button name, and send that as a message, grabbing the buttons name. in this case use llGetObjectName.

methods that use a script in the button do not need a script in the root prim (but may use one) and can redirect their messages elswhere (or just handle the procedure themselves) this allows a non touch root
benefit: IIRC only the buttons will show a touch cursor.
drawback: at least one script per button.

methods that use the root prim to handle touches don't require scripts in the buttons
benefit: single script handling all buttons
Drawback: everwhere on the object will show a touch icon, even if touching that particular prim won't trigger an action
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-18-2009 21:09
@EDIT:
every script is maintained independently, even within the same prim. if a script changes state, it will respond as the new state regardless of prior messages.

think of each state as a separate script, that shares global variables with all the other states in that script, and can only operate as one state at a time. each state will only handle the events and code included within it.

so if you switch states from one with a ling message event handler to one that doesn't, link messages are going to get ignored.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Ephraim Kappler
Reprobate
Join date: 9 Jul 2007
Posts: 1,946
11-27-2009 07:58
Apologies for pulling this one up again but how would I get a script to 'remember' whether or not one child prim has been touched when I'm touching another? For instance, in this short selection of listens, I wouldn't want the button saying message "2" to fire unless the button activating state one had been pressed first?

CODE

listen(integer channel, string name, key id, string message)
{
if (llGetOwnerKey(id) == llGetOwner())
{
if (message == "1")
{
llMessageLinked(-2, 0, "0", "");
state one;
}
else if (message == "2")
{
llMessageLinked(-2, 0, "0", "");
llMessageLinked(4, 0, "5", "");
}
else if (message == "3")
{
llMessageLinked(-2, 0, "0", "");
state two;
}
else if (message == "4")
{
llMessageLinked(-2, 0, "0", "");
llMessageLinked(8, 0, "7", "");
}
}
}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-27-2009 13:46
multiple states

CODE

state default{
touch_start( integer vIntTouchs ){
while (vIntTouches){
if (LlDetectedLinkNumber( vIntTouches ) == 2){
state sSeq1;
}else{
//-- other stuff
}
}
}
}

state sSeq1{
touch_start( integer vIntTouchs ){
while (vIntTouches){
if (LlDetectedLinkNumber( vIntTouches ) == 3){
//-- does stuff when prim 3 is touched, only after prim 2 is touched
}
}
}
}


single state

CODE

integer vBooFlag

state default
touch_start( integer vIntTouchs ){
while (vIntTouches){
if (LlDetectedLinkNumber( vIntTouches ) == 3 && vBooFlag){
//-- do stuff if prim 3 is touched, only if prim 2 has been touched
}else if (LlDetectedLinkNumber( vIntTouches ) == 2){
vBooFlag = TRUE;
}
}
}
}


you can also walk a counter to make your decision

CODE

integer vIntCounter;

state default
touch_start( integer vIntTouchs ){
while (vIntTouches){
if (vIntCount = 0){
//-- do 1
}else if (vIntCount = 1){
//-- do 2
}else if (vIntCount = 2){
//-- do 3
}
}
counter = (counter + 1) % 3; //-- mod 4 loops the counter
}
}
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -