Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Newbie Question: Self-disabling objects.

Edgar Ellison
Registered User
Join date: 18 Sep 2006
Posts: 13
10-15-2006 00:52
If I add an object "Thing" to the inventory of another object, but that container already has a "Thing", the new one will be renamed "Thing 1". I know I can write a script that says:

"If this inventory contains a Thing with a number higher than mine, delete me".

However, I may want to keep the old Things around for a while. How can I write a script that says:

"If this inventory contains a Thing with a number higher than mine, don't run any of my scripts".


My container also has a "rezzer" script that will, in response to a chat command, rez a new copy of Thing. It has to explicitly know the name of the object in its inventory. How do I tell it to rez the highest-number "Thing" in the inventory?
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
10-15-2006 02:54
I think you may be under the misapprehension that a script A inside an object B within the inventory of another object C can run. When in inventory, an object doesn't do anything, and scripts inside it don't do anything.

One way to identify the highest number Thing is to loop through the names of the objects in the inventory, using llGetInventoryName, in a for loop involving llGetInventoryNumber, and look for the highest number Thing (using something like (integer)llGetSubString(name, 6, -1)) you find.
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-15-2006 03:06
From: Edgar Ellison
My container also has a "rezzer" script that will, in response to a chat command, rez a new copy of Thing. It has to explicitly know the name of the object in its inventory. How do I tell it to rez the highest-number "Thing" in the inventory?



Without seeing your code I cant comment but I'd add code to the rezzer so it can work out if there is a numbered item. Something like this may work :

CODE

string GetLatestRevision(string name)
{
string result = name;
integer found = TRUE;
integer num = 1;
do
{
string newname = name + " " + (string)num;
integer itemtype = llGetInventoryType(newname);
if(INVENTORY_NONE == itemtype)
{
found = false;
}
else
{
result = newname;
++num;
}
}
while(found);
return result;
}


I'd be inclined to use an on change event to update a list of the revision numbers to use but again that would be dependant on how you have written your code. Of course if you have a large number of items and revisions it could be very slow.
Edgar Ellison
Registered User
Join date: 18 Sep 2006
Posts: 13
10-16-2006 01:19
Thanks for your advice, Newgate. Here's the original Rezzer script that I should have provided already. Note the line "string object1Name = "Object1"". Instead of that, I want it to set object1Name to Thing1, or Thing2, or Thing3, etc, whichever is highest that exists.

So, then, I guess I would replace it with string object1Name = GetLatestRevision(string "Thing";) (and, of course, add your code snippet too). Is that right?

//Deluxe Listen Rezzer
//Created By : Chasingred3 Ixtab
//Created For : Zippo Nabob
//No need to type in the right CaSe to make your
//Commands to work :)

integer channel = 0;//What channel you want it to listen on

////////////////////////////////////////////////////////////////////////////
/////////////////////////////////1st Object Info////////////////////////////
////////////////////////////////////////////////////////////////////////////
string object1command = "rez object1"; /////////////////////////////////
string object1Name = "Object1";//First objects name/////////////////////
vector object1Pos = <0,0,0>;//First Objects Position Cordanates////////
rotation object1rotation = <0,0,0,1>;//First Objects Rotation///////////
////////////////////////////////////////////////////////////////////////////

//==========================================================================

////////////////////////////////////////////////////////////////////////////
/////////////////////////////////2nd Object Info////////////////////////////
////////////////////////////////////////////////////////////////////////////
string object2command = "rez object2"; /////////////////////////////////
string object2Name = "Object1";//Objects name/////////////////////
vector object2Pos = <0,0,0>;//Objects Position - Cordanates////////
rotation object2rotation = <0,0,0,1>;//Objects Rotation///////////
///////////////////////////////////////////////////////////////////////

//==========================================================================

////////////////////////////////////////////////////////////////////////////
/////////////////////////////////3nd Object Info////////////////////////////
////////////////////////////////////////////////////////////////////////////
string object3command = "rez object3"; /////////////////////////////////
string object3Name = "Object3";//Objects name/////////////////////
vector object3Pos = <0,0,0>;//Objects Position - Cordanates////////
rotation object3rotation = <0,0,0,1>;//Objects Rotation///////////
///////////////////////////////////////////////////////////////////////

//==========================================================================

////////////////////////////////////////////////////////////////////////////
/////////////////////////////////4th Object Info////////////////////////////
////////////////////////////////////////////////////////////////////////////
string object4command = "rez object4"; /////////////////////////////////
string object4Name = "Object4";//objects name/////////////////////
vector object4Pos = <0,0,0>;//Objects Position - Cordanates////////
rotation object4rotation = <0,0,0,1>;//Objects Rotation///////////
///////////////////////////////////////////////////////////////////////

//==========================================================================

////////////////////////////////////////////////////////////////////////////
/////////////////////////////////5th Object Info////////////////////////////
////////////////////////////////////////////////////////////////////////////
string object5command = "rez object5"; /////////////////////////////////
string object5Name = "Object5";//Objects name/////////////////////
vector object5Pos = <0,0,0>;//Objects Position - Cordanates////////
rotation object5rotation = <0,0,0,1>;//Objects Rotation///////////
///////////////////////////////////////////////////////////////////////

//==========================================================================

//Please, Dont touch anything down here :P

//==========================================================================
//==========================================================================
//==========================================================================
string obj1 = "";
string obj2 = "";
string obj3 = "";
string obj4 = "";
string obj5 = "";

default
{
state_entry()
{//llGetOwner --- NULL_KEY
llListen(channel, "", llGetOwner(), "";);
string obj1 = llToLower(object1command);
string obj2 = llToLower(object2command);//Changes all commands to
string obj3 = llToLower(object3command);//lower case
string obj4 = llToLower(object4command);
string obj5 = llToLower(object5command);
}

listen(integer channel, string name, key id, string message)
{
string cmd;
cmd = llToLower(message);//Turnes what YOU say to lower
//case letters
if(cmd == obj1)
{
llRezObject(object1Name, object1Pos, ZERO_VECTOR, object1rotation, 42);

}
if(cmd == obj2)
{
llRezObject(object2Name, object2Pos, ZERO_VECTOR, object2rotation, 42);
}
if(cmd == obj3)
{
llRezObject(object3Name, object3Pos, ZERO_VECTOR, object3rotation, 42);
}
if(cmd == obj4)
{
llRezObject(object4Name, object4Pos, ZERO_VECTOR, object4rotation, 42);
}
if(cmd == obj5)
{
llRezObject(object5Name, object5Pos, ZERO_VECTOR, object5rotation, 42);
}
}

}
Edgar Ellison
Registered User
Join date: 18 Sep 2006
Posts: 13
10-16-2006 01:52
From: Seifert Surface
I think you may be under the misapprehension that a script A inside an object B within the inventory of another object C can run. When in inventory, an object doesn't do anything, and scripts inside it don't do anything.


Okay.

I'm trying to make a "Fruit Tree" that has five different types of fruit (objects) in its inventory. It also has a rezzing script that will make new copies of the fruit and drop them from the tree. When I make a new version of the RedFruit, I will drop it into the tree's inventory, and it will be automatically named "RedFruit 1".

The rezzing script that I currently have will still operate only on the original RedFruit. The suggestions on this board will help me change the script so that it operates on the highest-numbered RedFruit.

Now here's a new question: the lslWiki script library has a two different scripts which automatically update scripts in child prims. For instance, I can put a new version of a script in my original Fruit Tree, and have it upgrade that script in all the nearby Fruit Trees.

Is there a way to do that with objects? When I put the new version of RedFruit in the original Tree, can I have it appear in all nearby Trees as well?