Lasivian Leandros
Hopelessly Obsessed
Join date: 11 Jul 2005
Posts: 238
|
08-23-2005 12:47
I'm trying to make a script you can drop into a prim and it'll delete the contents. If you're asking why, several times now i've made very complicated prims and wanted to duplicate them without rebuilding them, but not their contents. If anyone has a script that can do this or can sort my attempt out i'd appreciate it. This is what i've got so far, but I can't stop it from deleting itself before it should. Thanks float time = 0; integer total; integer counter; next() { string name = llGetInventoryName(INVENTORY_ALL,counter); if(name == "") { total = llGetInventoryNumber(INVENTORY_ALL); counter = 0; if(total < 1) return; else name = llGetInventoryName(INVENTORY_ALL,counter); } else if(counter + 1 >= total) total = llGetInventoryNumber(INVENTORY_ALL); llRemoveInventory(name); if(total) counter = (counter + 1) % total; } default { state_entry() { total = llGetInventoryNumber(INVENTORY_TEXTURE); next(); llSetTimerEvent(time); } timer() { next(); } }
_____________________
From: someone "SL is getting to be like a beat up old car with a faulty engine which keeps getting a nice fresh layer of paint added on, while the engine continues to be completely unreliable." - Kex Godel
|
Minsk Oud
Registered User
Join date: 12 Jul 2005
Posts: 85
|
08-23-2005 13:00
The *really* quick fix is to replace "llRemoveInventory(name);" with if (name != llGetScriptName()) llRemoveInventory(name)
For a longer tweak that simplifies the code: try always deleting the first element until you find the script there, then always deleting the second element. Finally, delete the script.
_____________________
Ignorance is fleeting, but stupidity is forever. Ego, similar.
|
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
|
08-23-2005 13:37
In this situation, I name my script something like, "zzScript Name," so that it's always at the bottom of the object's contents. Then, I subtract 1 from total:
total = llGetInventoryNumber(INVENTORY_ALL) - 1;
But, that doesn't work well if someone else can come along and rename the working script, though. I use it in inventory-giver containers so that all the contents are given, but not the script.
|
Lasivian Leandros
Hopelessly Obsessed
Join date: 11 Jul 2005
Posts: 238
|
08-23-2005 13:54
This works perfectly. string gText = ""; // Put new Floating Text here, leave blank for no text string gName = ""; // Put new Name here, leave blank for no text string gDesc = ""; // Put new Description here, leave blank for no text // You shouldn't need to change antyhing below here float time = .1; // Sets the time between file deletes, CANNOT BE ZERO or it won't delete anything. integer total; integer counter; next() { string name = llGetInventoryName(INVENTORY_ALL,counter); if(name == "") { total = llGetInventoryNumber(INVENTORY_ALL); counter = 0; if(total == 1) llRemoveInventory(llGetScriptName()); else name = llGetInventoryName(INVENTORY_ALL,counter); } else if(counter + 1 >= total) total = llGetInventoryNumber(INVENTORY_ALL); if(name != llGetScriptName()) llRemoveInventory(name); if (total) counter = (counter + 1) % total; } default { state_entry() { llSetText(gText, <1,1,1>, 1.5); llSetObjectName(gName); llSetObjectDesc(gDesc); total = llGetInventoryNumber(INVENTORY_ALL); next(); llSetTimerEvent(time); } timer() { next(); } }
_____________________
From: someone "SL is getting to be like a beat up old car with a faulty engine which keeps getting a nice fresh layer of paint added on, while the engine continues to be completely unreliable." - Kex Godel
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
08-23-2005 14:46
I just use this... does a really nice quick job of emptying the inventory and it's fast. default { state_entry() { string me = llGetScriptName(); string name; while((name = llGetInventoryName(INVENTORY_ALL, 0)) != me) llRemoveInventory(name); integer a = llGetInventoryNumber(INVENTORY_ALL); while(--a) llRemoveInventory( llGetInventoryName(INVENTORY_ALL, 1)); llRemoveInventory(me); } }
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
08-23-2005 16:00
My version: integer i; string me = llGetScriptName(); for (i = llGetInventoryNumber(INVENTORY_ALL) - 1; i >= 0; --i) { string name = llGetInventoryName(INVENTORY_ALL, i); if (name != me) llRemoveInventory(name); } llRemoveInventory(me);
A little simpler but slower then Strife's, though I like the way he avoids the string comparison when the first item in inventory is the deleter script.
|