Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Inv Management problem

Krista Chaffe
Registered User
Join date: 16 Jun 2007
Posts: 96
02-18-2008 18:13
Here is bit of code that is driving me nuts [some debug left in]

It is supposed to delete all scripts in a prim, then delete itself.

What it does is delete 4, then stop. When it reaches i=4, the length of the name is 0 and it exits the loop and kills itself. The trace prints say what I expect except the scripts it does delete are not in alpha order [llGetInventoryName, says it should return in alpha order not that I care]

Leaving 2 scripts.

Anybody have a clue what I've messed up, debug trace at end of post

================================================

default
{
state_entry
{
integer i;
string name;
string ServerScript;
integer NameSize = 1;

ServerScript = llGetScriptName();
llSay(0, "Script name = "+ServerScript);

for (i=0;NameSize > 0; i++)
{
name = llGetInventoryName(INVENTORY_SCRIPT, i);
NameSize = llStringLength(name);
llSay(0," Index = "+(string)i+" Size = "+(string)NameSize);
if ((llStringLength(name) > 0) && (name != ServerScript))
{
llSay(0, "Deleting Script = "+name);
llRemoveInventory(name);
}
}
llSay(UpdateChan, "Purged";);
llRemoveInventory("Purge";);
}
}

=========================================

Script name = Purge
Index = 0 Size = 16
Deleting Script = AvController 4.1
Index = 1 Size = 21
Deleting Script = AvScannerDomestic 4.0
Index = 2 Size = 16
Deleting Script = Configurator 4.1
Index = 3 Size = 17
Deleting Script = Show Coverage 2.0
Index = 4 Size = 0
Grey Lock
Dragon
Join date: 16 Oct 2006
Posts: 35
02-18-2008 19:04
From: someone
name = llGetInventoryName(INVENTORY_SCRIPT, i);


Wouldn't i at some point exceed the number of inventory script items as they are being deleted as you cycle through the loop?
Krista Chaffe
Registered User
Join date: 16 Jun 2007
Posts: 96
02-18-2008 19:55
So i is relative to the number of scripts when you make the call &^****%%$###

dang it, thank you
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-18-2008 22:01
I kinda like this style:

CODE

integer nScripts = llGetInventoryNumber(INVENTORY_SCRIPT);
string thisScript = llGetScriptName();
string firstScript = llGetInventoryName(INVENTORY_SCRIPT, 0);
while (firstScript != thisScript)
{
llRemoveInventory(firstScript);
--nScripts;
firstScript = llGetInventoryName(INVENTORY_SCRIPT, 0);
}
while (nScripts > 1)
{
llRemoveInventory(llGetInventoryName(INVENTORY_SCRIPT, 1));
--nScripts;
}
llRemoveInventory(thisScript);
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
02-18-2008 23:52
Do the deletion loop backwards and you'll get something that is made of win.

A.k.a. Count down.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-19-2008 01:40
or build a list of items, remove your own script from that list, then loop through deleting them, then delete your script
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Sho Iuga
Registered User
Join date: 6 Jun 2007
Posts: 35
02-19-2008 04:21
Just for illustration. This is the code Squirrel Wood had in mind.

CODE

integer n = llGetInventoryNumber(INVENTORY_SCRIPT);
string thisScript = llGetScriptName();
while (n--)
{
string nthScript = llGetInventoryName(INVENTORY_SCRIPT, n);
if(nthScript != thisScript) llRemoveInventory(nthScript);
}
llRemoveInventory(thisScript);
Krista Chaffe
Registered User
Join date: 16 Jun 2007
Posts: 96
02-19-2008 09:04
Thanks for the help.

After the slap around the head, it was no problem. I had spent the day doing database programming in RL and was thinking SQL not LSL