Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
08-14-2003 15:47
//Special thanks to Lance LeFay, Bosozoku Kato, and Ironchef Cook who helped me out with debugging this function integer getNumLinks() //returns the number of objects linked to object calling function. { if(llGetLinkKey(0) != NULL_KEY) return -1; //Object is alone
else { integer i = 1; //skip 0, since 0 is already checked while(TRUE) { if(llGetLinkKey(i) == NULL_KEY) { return i - 2; //the object script is on, and the number that returned NULL_KEY } else { i++; } } } }
A simple variation on the function above can return the total number of objects in the linked set, instead of the objects linked to the function caller object, simply change return i - 2; to return i - 1; -Chris
|
Grim Lupis
Dark Wolf
Join date: 11 Jul 2003
Posts: 762
|
Re: getNumLinks() //gets the number of linked objects attached to object
08-14-2003 16:35
Some "improvements"  integer getNumLinks() //returns the number of objects //linked to object calling function. { if(llGetLinkKey(0) != NULL_KEY) return -1; //Object is alone
else { integer i = 3; //skip 0, since 0 is already checked. //since you checked 0, you already know //that 1 & 2 exist, too. (1=root, 2=first child) while(TRUE) { if(llGetLinkKey(i++) == NULL_KEY) { return i - 3; //the object script is on, //and the number that returned //NULL_KEY, and the extra increment } } } }
_____________________
Grim
"God only made a few perfect heads, the rest of them he put hair on." -- Unknown
|