Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How do I return unique values from a list?

Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
12-28-2008 06:15
I'm making a holodeck rezzer, which is working pretty much to my satisfaction, but I would greatly appreciate some help with tweaking it.

At the moment, I give all the objects that are to go in a particular scene the same name -- e.g. sceneA -- and let SL rename them sceneA, sceneA 1, sceneA 2, and so on when I put them in the rezzer's inventory. I also put the name of the scenes on a notecard in the prim's inventory and read that to generate llDialog menus at run time. When I choose a scene, the script uses Very Keynes' nifty "like" function -- http://wiki.secondlife.com/wiki/Like -- to loop through my inventory list and pull out everything with a name that starts "sceneA " to rez.

As I say, this is working well, but I am just wondering if I can't dispense with the notecard altogether and just loop through my inventory to pull out unique names and build the menus that way.

Well, I'm sure it's possible, but I can't figure out how to do it, and would greatly appreciate some advice.

I'm playing with the idea of using llList2String to loop through the alphabetized inventory list, adding values to my MENU_BUTTONS list as it goes if the first n letters of the value it's considering aren't identical to the whole string it's just added. But I suspect there's a better way to do this.
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
12-28-2008 08:22
Take a look at my DBMS code, the project I was working on that the Like function was part of, it is not so much a solution as a set off tools that may well help with your project.

/54/4a/290413/1.html

The documentation and Sample programs are here:

http://docs.google.com/Doc?id=d79kx35_26df2pbbd8
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
12-28-2008 11:12
Check out the inventory functions here:

http://wiki.secondlife.com/wiki/Category:LSL_Inventory

In particular, you'll want:

http://wiki.secondlife.com/wiki/LlGetInventoryNumber
http://wiki.secondlife.com/wiki/LlGetInventoryName

For example, to iterate through the textures in your prim's inventory, you can do something like:

CODE

integer nTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
integer i;
for (i = 0; i < nTextures; ++i)
{
string textureName = llGetInventoryName(INVENTORY_TEXTURE, i);
// Do something with textureName
}
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
12-28-2008 14:10
Thanks, both..
CODE

list buttons =[];
integer nObjects = llGetInventoryNumber(INVENTORY_OBJECT);
string curName = llGetInventoryName(INVENTORY_OBJECT, 0);
buttons += curName;
integer i;
for (i = 1; i < nObjects; ++i)
{
string objectName = llGetInventoryName(INVENTORY_OBJECT, i);
integer n = llStringLength(curName);
if (llGetSubString(objectName,0,n-1) != llGetSubString(curName,0,n-1))
{
buttons +=objectName;
curName = objectName;
}
else curName=curName;

}
seems to do the trick, though I am sure there is a more elegant way of doing it.