This code is extracted from my animation library, where vertice need BoneIndex to setup weightmaps , i think it must be the same kind of function you want
+> Return the Bone (using Index)
/!\ the function self-return <0 to get the number of bones in the branch else, if return is >0 then it is the Bone pointer
So, if the index is higher than the global countchildren, then, it will return <0
Eventually you will want to check:
Bone=GetSubChild(Entity,Index)
If Bone>0 ...
Function GetSubChild%(Entity%,BoneId%,Count%=0)
If Count=BoneId Return Entity
Count=Abs(Count)+1
For n=1 To CountChildren(Entity)
Bone=GetSubChild(GetChild(Entity,n),BoneId,Count)
If Bone>0 Return Bone
If Bone<0 Count=-Bone
Next
Return -Count
End Function
If you pass BoneIndex=0 then it will return the Entity... not useless ^^, but that is probably the fastest way to do it without global variables