Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Comments, user changable variables in inventory names.

Gearsawe Stonecutter
Over there
Join date: 14 Sep 2005
Posts: 614
08-25-2006 23:40
I have been using the old notecard method for a long time now for people to input data into a script. It has always been slow and I guess it is not great for the data server either. So I have been playing with this idea. You have your main script and a bunch of inventory items with comma separated values. Now what I don't know is what would be the best Inventory Type to use which would use the least amount of sever resources.

Inventory Setup:
X,1
Y,1
Z,1
Main script

the code..
CODE
float x;
float y;
float z;

UpdateVars(){
integer total_inv = llGetInventoryNumber(INVENTORY_TEXTURE);
integer i;
list list_name;
string inv_name;
float val;
for (i = 0; i < total_inv; i++)
{
list_name = llCSV2List(llGetInventoryName(INVENTORY_TEXTURE,i));
inv_name = llList2String(list_name, 0);
val = llList2Float(list_name, 1);
if (inv_name == "X") x = val;
if (inv_name == "Y") y = val;
if (inv_name == "Z") z = val;
}
}

default
{
state_entry()
{
UpdateVars();
llSetScale(<x,y,z>);
}
changed(integer change)
{
if (change & CHANGED_INVENTORY)
{
UpdateVars();
llSetScale(<x,y,z>);
}
}
}

Now would this seem more or less sim friendly than reading lines from a notecard?
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
08-26-2006 01:04
Don;t these all need to exist on the asset server? I would have thought the asset server has much bigger problems than your sim. Once you read the first line of the notecard, your sim should cache that notecard copy and from there just read subsequent lines from it cached copy. Maybe someone else can comment.
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
08-26-2006 07:51
Just inventory information for a rezzed object itself (ie what's in an object's inventory, what the inventory items' names are, etc) is not stored on the asset server, as far as I know.

This is a really clever idea, Gearsawe! I think it almost HAS to be better than reading lines from a notecard, because it doesn't have to go outside of the sim for the information. Inventory stuff is not done through the dataserver, so it is much quicker. There's no time delay built into inventory functions, so we can infer that they don't have a huge overhead for the sim.

As to which inventory type to use, I don't think it matters at all. It might be slightly more efficient to use "INVENTORY_ALL", and throw out any items that don't look like variables, because then the sim doesn't have to check the inventory type of each object. Kind of a pointless and niggling optimization though.

All in all, given the way that you update the variables only on a changed() event, I think this is fairly efficient. It's excellent for setting small variables in a script, because the data's all right there. I've been wishing for a way to set arbitrary variables on an object without using a notecard's contents... but I never thought of something like this!
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
08-26-2006 08:27
I've been using the names of notecards to store values of some variables for a while, it's done mainly for the user convenience though (renaming the item is less clicks than opening the card, tracking down the variable, changing, saving etc) ... as far as performance goes didn't see much of difference, but then i try to limit this way to define variables only to few items that may need common changes, to avoid inventory clutter. As everything, it's for some uses, not good for some other ^^;;

(one thing to keep in mind is, everyone can see your variables defined in such way by right-click->edit on your object... so it's only good for things you don't mind people seeing)
Norman Desmoulins
Grand Poohba
Join date: 10 Nov 2005
Posts: 194
08-26-2006 08:51
If you want to hide/protect your main script then you can create an secondary script with full perms that contains the variables that you want the user to change. The values can then be sent/queried using link messages. I do that now for my build database, mainly because of memory (each script gets 16K).
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
Object Description...
08-26-2006 09:01
The object description is also a good place to put variables, because you can edit it in yuor inventory before you even rez the object!

I just bought a teleporter that does this, and I'm going to make my own do the same thing when I get a chance to hack on it again. It's really convenient... I just make several copies in my inventory and go around the sim putting the destinations right there, then when I rez one it's already configured!