Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llDetectedLinkNumber

Cashmere Falcone
Prim Manipulator
Join date: 21 Apr 2004
Posts: 185
10-28-2004 20:11
Anyone have a script that returns the LinkNumber of a prim within an object? I have messed with this all evening, and for the life of me, cannot make one that works.
_____________________
Jebus Linden for President! :p
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-28-2004 20:39
CODE

default
{
touch_start(integer a)
{
for(;a;a--)
llSay(0."Link Touched: "+ (string)llDetectedLinkNumber(a - 1));
}
}


or to be evil :p

CODE

default
{
touch_start(integer a)
{
while(a)
llSay(0."Link Touched: "+ (string)llDetectedLinkNumber(--a));
}
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Cashmere Falcone
Prim Manipulator
Join date: 21 Apr 2004
Posts: 185
10-29-2004 03:50
Excellent, 2nd one works, thanks! :)
_____________________
Jebus Linden for President! :p
Fairge Kinsella
Gravity isn't so serious!
Join date: 23 Oct 2004
Posts: 158
03-23-2005 15:58
I am starting to feel very silly, but I don't understand why you have to decrement a before getting the link number?
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
03-23-2005 16:16
The decrement has nothing to do with the links, but rather, how touch works. Strife's solution is there to compensate for events where more than one avatar is touching the object. Hence, the decrement and while loop are there to check for each touch occurance.
_____________________
---
Fairge Kinsella
Gravity isn't so serious!
Join date: 23 Oct 2004
Posts: 158
03-23-2005 16:48
Thanks, Jeffery. What I'm not understanding it why you decrement a before calling llDetectedLinkNumber()

For example, if two avatars touch the object:

while(a) // true, a=2
llSay(0."Link Touched: "+ (string)llDetectedLinkNumber(--a)); // says the link no for touch #1
while(a) // true, a=1
llSay(0."Link Touched: "+ (string)llDetectedLinkNumber(--a)); // says the link no for touch #0, but there is no touch 0?
while(a) // false, a=0

So it will report twice, there are two touches, fair enough.


But it fails if I use:

while(a)
{
llSay(0."Link Touched: "+ (string)llDetectedLinkNumber(a));
a--;
}

I've only tested with one touch, and no matter which prim in the linked object I touch, llDetectedLinkNumber() returns 0.

So it works using the Strife's code, but it's giving me the heebie-jeebies that I don't understand why my example doesn't work.

Thanks again,
Fairge
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
03-23-2005 16:58
It's because the 'a' returns the total number for a zero-indexed array; basically:


Total Number = 5

0 => Link 1
1 => Link 2
2 => Link 3
3 => Link 4
4 => Link 5

-Adam
_____________________
Co-Founder / Lead Developer
GigasSecondServer
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
03-23-2005 17:00
there are a couple things going on.

CODE

default
{
touch_start(integer a)
{
while(a)
llSay(0."Link Touched: "+ (string)llDetectedLinkNumber(--a));
}
}


nicely writen becomes...

CODE

default
{
touch_start(integer num)
{
while(num != 0)
{
--num;
llSay(0."Link Touched: "+ (string)llDetectedLinkNumber(num));
}
}
}


you see the first touch is numbered zero; the second, one; the third, two. This is the standard in computing. Now the paramater is (num) is how many there are total in the stack. The last entry is (num - 1). This script reads the stack backwords. In most cases in scripting it won't matter which way you read it (the sensor event sorts the entries by how close they are).

So first we test to make sure we haven't run out of entries. Then subtract one.
Then use that to get the last entry of the stack we haven't gotten before.

See i'm lazy, if i can avoid decaring variables at the expense of read backwords thats fine with me :p
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Fairge Kinsella
Gravity isn't so serious!
Join date: 23 Oct 2004
Posts: 158
03-23-2005 17:38
Got it now, thanks for the clear explanations. I'd mixed it up, and thought that touch_start was giving me an index number, not a count. <grin>

And it is splendid how helpful you all are!

Cheers,
Fairge
Zalandria Zaius
Registered User
Join date: 17 Jan 2004
Posts: 277
an even lazier way..
03-24-2005 08:14
default
{
touch_start(integer total_number)
{
llSay(0,(string)llDetectedLinkNumber(total_number - 1));
}
}


If you're going to have multiple people click it, this may not be a good way, but it does spit out the link number if you're just trying to get it to use in linked messages and stuff.
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
03-24-2005 10:33
Strife's being clever. It's a bit more readable like this, and it's probably not any noticeably less efficient:

CODE

default
{
touch_start(integer num_touching)
{
integer i;
for(i=0; i<num_touching; i++)
llSay(0."Link Touched: "+ (string)llDetectedLinkNumber(i));
}
}