Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Mysterious (to me) problems with llGiveInventory

Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
11-19-2008 08:19
The answer is probably staring me in the face, but I cannot figure this out. Why should

CODE

touch_start(integer total_number)
{
key av = llGetOwner();


integer max = llGetInventoryNumber(INVENTORY_OBJECT);
llOwnerSay((string) max);
integer n;
for(n=0; n<max; n++)
{
llOwnerSay(llGetInventoryName(INVENTORY_OBJECT, n));
}

integer i =0;
for (i = 0; i < max; i++)
{
llOwnerSay("giving "+llGetInventoryName(INVENTORY_OBJECT, i));
if (llGetInventoryName(INVENTORY_OBJECT, i)!="")
{
llGiveInventory(av, llGetInventoryName(INVENTORY_OBJECT, i));


}


}

}


give me the following results (I've cut out the bits about accepting and declining things):

8:03] Object: 6
[8:03] Object: Lovers Entanglement 1.0
[8:03] Object: Tree 1
[8:03] Object: Tree 3
[8:03] Object: Tree 2
[8:03] Object: Tree 4
[8:03] Object: Tree 5
[8:03] Object: giving Lovers Entanglement 1.0
[8:03] Object: giving Tree 1
[8:03] Object: giving Tree 3
[8:03] Object: giving Tree 5
[8:03] Object: giving
[8:03] Object: giving

then I have to touch it again, and..
[8:03] Object: 3
[8:03] Object: Lovers Entanglement 1.0
[8:03] Object: Tree 2
[8:03] Object: Tree 4
[8:03] Object: giving Lovers Entanglement 1.0
[8:03] Object: giving Tree 2
[8:03] Object: giving Tree 4

I want it, obviously, to give me all the objects in one go.

The permissions, as it happens, were Trees 1,3,5 no copy and 2&4 copy but I got exactly the same results when they were all no copy (a friend made the objects, so was able to give them to me with different permissions). And because they are not supposed to be copyable, I can't use llGiveInventoryList, of course.

Why is it getting the contents right when it says what they are but not when it uses the identical function to give them to me?
Dasolo Sautereau
Registered User
Join date: 22 Aug 2007
Posts: 2
11-19-2008 10:53
Yes, the answer was staring at your face -:)
You give Tree 1 which is NO COPY. In the object's inventory Tree 3 is the next sequence number in the FOR loop. Not Tree 2 because it has the same sequence number as Tree 1 when this one is not anymore there.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
11-19-2008 12:25
Thank you so much. I thought I was going crazy. There's probably a more elegant way to do it, but this seems to work:
CODE
  touch_start(integer total_number)
{
key av = llDetectedKey(0);
list mylist;
integer max = llGetInventoryNumber (INVENTORY_OBJECT);
integer i;
for (i = 0; i < max; i++)
{
mylist += llGetInventoryName(INVENTORY_OBJECT, i);
}

integer n;
for (n = 0; n < max; n ++)

{
llGiveInventory(av, llList2String(mylist, n));
}

}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
11-19-2008 13:05
Reverse the order of the for next loop:
for (i = max-1; i >=0; i--) instead of: for (i = 0; i < max; i++)
this way the indexing will not be disturbed when you give out a no copy inventory item:)
_____________________
From Studio Dora
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
11-19-2008 13:11
Thank you, Dora. I knew there must be a more elegant way than mine to do it, and you have show me.