Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Trouble with a llGiveInventory

Luxette Maximus
:3~
Join date: 25 Dec 2007
Posts: 16
01-26-2010 11:38
I'm not very good at scripting and i've been having troubles with the following script. I've been looking in the library and in the LSLwiki but it seems i fail at make it work as i want. ;_;

What i want to do it's when clicked the box(prim) send a folder with the inventory content from it. Only to the owner of the box and i want the folder in the inventory had the same name from the box (prim) where he or she clicked on. So when they look in their inventory there's a folder called for example: prim1 with its content, so it would be easier for them to search the content im giving. I wish the box would also tell to the person that the contents are now in their inventory with the following name (the name from the prim/box).

Thank you so much in advance!

CODE
string gFolder = "objectname";

key gowner;
key gtoucher;
integer gx;
integer gcount;
list gtextures;

default
{
on_rez(integer param)
{
llResetScript();
}

state_entry()
{
gowner = llGetOwner();
gcount = llGetInventoryNumber(INVENTORY_ALL);
for (gx = 0; gx < gcount; gx++)
{
gtextures = (gtextures = []) + gtextures + [llGetInventoryName(INVENTORY_ALL, gx)];
}
}

touch_start(integer total_number)
{
gtoucher = llDetectedKey(0);
if (gtoucher == gowner)
{
llGiveInventoryList(gowner, gFolder, gtextures);
}
}
}
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
01-26-2010 11:50
Although there's a few bits you could do to make it neater, I don't see anything obviously wrong with it. Then again, I've never used llGiveInventoryList..

Are you just looking to get the folder name the same same the object? If so, I think you just want to do this:

llGiveInventoryList(llGetOwner(), llGetObjectName(), gtextures);


...or is there something else wrong?

edit: and you probably want to add this bit so you pick up on changes to the inventory after the script resets:

changed (integer mask)
{
if (mask & CHANGED_INVENTORY)
{
llResetScript();
}
}
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-26-2010 11:58
So what's not working? Your script seems to compile OK. Do you just want it to say what's in it and then tell the buyer that s/he has just received a folder? If so, then add llSay or llOwnerSay statements in a couple of spots. For example ....

CODE

for (gx = 0; gx < gcount; gx++)
{
llSay(0,llGetInventoryName(INVENTORY_ALL,gx));
gtextures = (gtextures = []) + gtextures + [llGetInventoryName(INVENTORY_ALL, gx)];
}


and

CODE

if (gtoucher == gowner)
{
string gFolder = llGetObjectName();
llGiveInventoryList(gowner, gFolder, gtextures);
llOwnerSay("Look in your inventory for a new folder named " + gFolder);
}


and remove gFolder from your list of global variables, since it doesn't need to be global if you do this.

As an aside, you might try visiting the Virtual Learning Library in the NW corner of the Info Island sim. (I'd give you a SLURL but I can't get in world to grab it right now. Use your map.) Go to the Scripting collection on the second floor and look for the two boxes of freebie scripts. Among other things, these contain a couple of vendor scripts you might be able to use or learn from, plus a script that displays an object's contents in scrolling hover text.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
01-26-2010 12:24
Likely, your problem is here:

CODE
touch_start(integer total_number) {
gtoucher = llDetectedKey(0);
if (gtoucher == gowner) {
llGiveInventoryList(gowner, gFolder, gtextures);
}

}


Since you set gowner in state_entry(), it will have your key in it. When you give/sell it to someone else, it will still have your key.

Replace the highlighted line(s) above with:

CODE

if (gtoucher == llGetOwner()) {
llGiveInventoryList(llGetOwner(), gFolder, gtextures);
}


Meade's solution will work, too, unless you have other reasons for not resetting the script upon selling/transferring the product.
Luxette Maximus
:3~
Join date: 25 Dec 2007
Posts: 16
01-26-2010 12:34
Thank you so much for your help guys.
I did have troubles editing again the script, with this fix
CODE
if (gtoucher == llGetOwner()) {
llGiveInventoryList(llGetOwner(), gFolder, gtextures);
}
it compiled but it isnt working.

I was trying also Roling's options but im having troubles with setting again the list of variables. (Also thank you for the suggestion for the place, im heading over).

CODE
string gFolder = "objectname"; //such a pain

key gowner;
key gtoucher;
integer gx;
integer gcount;
list gtextures;

default
{
on_rez(integer param)
{
llResetScript();
}

state_entry()
{
gowner = llGetOwner();
gcount = llGetInventoryNumber(INVENTORY_ALL);
for (gx = 0; gx < gcount; gx++)
{
gtextures = (gtextures = []) + gtextures + [llGetInventoryName(INVENTORY_ALL, gx)];
}
}

touch_start(integer total_number)
{
gtoucher = llDetectedKey(0);
if (gtoucher == llGetOwner()) {
llGiveInventoryList(llGetOwner(), gFolder, gtextures);
}
}
}
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-26-2010 12:37
Nice catch. :)
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
01-26-2010 12:38
How's this work?

CODE

list gtextures;

default
{
on_rez(integer param)
{
llResetScript();
}

changed (integer mask)
{
if (mask & CHANGED_INVENTORY)
{
llResetScript();
}
}

state_entry()
{
integer gcount = llGetInventoryNumber(INVENTORY_ALL);
integer gx;

for (gx = 0; gx < gcount; gx++)
{
gtextures = (gtextures = []) + gtextures + [llGetInventoryName(INVENTORY_ALL, gx)];
}
}

touch_start(integer total_number)
{
if (llDetectedKey(0) == llGetOwner())
{
llInstantMessage (llGetOwner(), "Here, have a folder named '" + llGetObjectName() + "'!!");
llGiveInventoryList(llGetOwner(), llGetObjectName(), gtextures);
}
}
}
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-26-2010 12:43
Meade's cleaned-up version will work fine. If you still want to tell the user what's going on, just pop the llSay and llOwnerSay statements I suggested into her script and you should be good to go.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Luxette Maximus
:3~
Join date: 25 Dec 2007
Posts: 16
01-26-2010 12:52
From: Meade Paravane
How's this work?

CODE

list gtextures;

default
{
on_rez(integer param)
{
llResetScript();
}

changed (integer mask)
{
if (mask & CHANGED_INVENTORY)
{
llResetScript();
}
}

state_entry()
{
integer gcount = llGetInventoryNumber(INVENTORY_ALL);
integer gx;

for (gx = 0; gx < gcount; gx++)
{
gtextures = (gtextures = []) + gtextures + [llGetInventoryName(INVENTORY_ALL, gx)];
}
}

touch_start(integer total_number)
{
if (llDetectedKey(0) == llGetOwner())
{
llInstantMessage (llGetOwner(), "Here, have a folder named '" + llGetObjectName() + "'!!");
llGiveInventoryList(llGetOwner(), llGetObjectName(), gtextures);
}
}
}


It worked perfectly! Thank you!!
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
01-26-2010 13:01
You're welcome!

Do you see what I did differently?
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left