Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Finding the Name of Dropped Texture!

Lazersam Hax
Registered User
Join date: 2 Jun 2007
Posts: 9
09-06-2008 12:10
Hi
I am writing a script that will allow people to Ctrl and drag a texture to a prim and that texture to be displayed on the prim. Thing is.. I am unable to indentify what texture has just been dropped into the inventory. The inventory rearranges the texture in alphabetical order list so I can't just pick the last in the list! Any ideas?

Thanks
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-06-2008 12:35
i remember reading somewhere about using the list feature to keep track of what contents are in the prim, and when something new is added, it compares that list to the new list to see what's new (alternatively, it can also be scripted to tell you which one was removed i think)
Lazersam Hax
Registered User
Join date: 2 Jun 2007
Posts: 9
09-06-2008 12:39
Thank you Ruthven, thats a good way! I'll try it.
Lazersam Hax
Registered User
Join date: 2 Jun 2007
Posts: 9
09-06-2008 13:39
That leads me to my next question LOL... anyone got a easy way to compare two lists and pull the data NOT listed in both?
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
09-07-2008 01:49
From: Lazersam Hax
That leads me to my next question LOL... anyone got a easy way to compare two lists and pull the data NOT listed in both?

One of these functions should do it

CODE

//list logic
//By Very Keynes - Please use or modify freely
//
list l1 = ["a","b","c","d"]; //test lists
list l2 = ["a","1","b","2","c","3"];

list ListXorY(list lx, list ly) // add the lists eleminating duplicates
{
list lz = []; integer x;
for (x = 0; x < llGetListLength(ly); ++x)
{
if ((integer)~llListFindList(lx,llList2List(ly,x,x))){;}
else {lz = lz + llList2List(ly,x,x);}
}
return lx + lz;
}

list ListXandY(list lx, list ly) // return a list of elements common to both lists
{
list lz = []; integer x;
for (x = 0; x < llGetListLength(ly); x++)
{
if ((integer)~llListFindList(lx,llList2List(ly,x,x))){lz = lz + llList2List(ly,x,x);}
else {;}
}
return lz;
}

list ListXnotY(list lx, list ly) // return elements in X that are not in Y
{
list lz = []; integer x;
for (x = 0; x < llGetListLength(lx); x++)
{
if ((integer)~llListFindList(ly,llList2List(lx,x,x))){;}
else {lz = lz + llList2List(lx,x,x);}
}
return lz;
}

list ListXxorY(list lx, list ly) // reteurn elements that are in X or Y but not both
{
return ListXnotY( lx, ly) + ListXnotY( ly, lx);
}

integer ListXequY(list lx, list ly)
{
if(llList2CSV(ListXnotY(lx,ly))=="")return TRUE;
else return FALSE;
}

integer ListXneqY(list lx, list ly)
{
if(llList2CSV(ListXnotY(lx,ly))=="")return FALSE;
else return TRUE;
}

default
{
state_entry()
{
llOwnerSay("testing functions");
llOwnerSay("Elements in x = " + llList2CSV(l1));
llOwnerSay("Elements in y = " + llList2CSV(l2));
llOwnerSay("Elements in x or y = " + llList2CSV(ListXorY(l1,l2)));
llOwnerSay("Elements in both x and y = " + llList2CSV(ListXandY(l1,l2)));
llOwnerSay("Elements that are in x but not in y = " + llList2CSV(ListXnotY(l1,l2)));
llOwnerSay("Elements that are in y but not in x = " + llList2CSV(ListXnotY(l2,l1)));
llOwnerSay("Elements that are in x or y but not both = " + llList2CSV(ListXxorY(l1,l2)));
llOwnerSay("list x == y = " + (string)ListXequY(l1,l2));
llOwnerSay("list x == x = " + (string)ListXequY(l1,l1));
llOwnerSay("list y != x = " + (string)ListXneqY(l2,l1));
llOwnerSay("list y != y = " + (string)ListXneqY(l2,l2));

}
}
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
09-07-2008 02:16
From: Ruthven Willenov
i remember reading somewhere about using the list feature to keep track of what contents are in the prim, and when something new is added,

Here's what I use to do that, which I found as part of the collection of his scripts that the code poet ZenMondo has very generously posted at http://lslwiki.net/lslwiki/wakka.php?wakka=ZenMondo
CODE
////////////////////////
// Function GetNewInventoryName by ZenMondo Wormser
//
// This function returns a list of the names of
// inventory items added to an object's inventory
// since the last time the function was called.
//
// This function works by keeping a list of inventory items
// and comparing against that list as inventory changes.
//
// NOTE: If items are deleted between calls and nothing is added
// this function will return an empty list.
////////////////////////

list gOld_Inventory; //This stores the Inventory since the last function call.
//It is global so it persists between function calls.
//It may also be handy to have a list of your object's inventory.

list GetNewInventoryName()
{
list found_new = []; //This list will contain the names of New Inventory items.
integer inventory_type = INVENTORY_ALL; //Change to look at inventory type you want.

integer inventory_num = llGetInventoryNumber(inventory_type);


list new_inventory = []; //This list will contain the current inventory.
integer counter = 0;

while(counter < inventory_num)
{
new_inventory = (new_inventory=[]) + new_inventory + llGetInventoryName(inventory_type, counter);
counter ++;
}

integer list_length = llGetListLength(new_inventory);

counter = 0;

list scratch;

while(counter < list_length)
{
scratch = llList2List(new_inventory, counter, counter);

if(llListFindList(gOld_Inventory, scratch) == -1) //New Inventory Object
{

found_new += llList2String(scratch,0); //Add the name of the new inventory item to the found_new list
}

counter ++;


}

gOld_Inventory = new_inventory; //Store the Inventory List to be compared the next time the function is called.
return found_new; //Return a list of the new inventory items.
}

default
{
state_entry()
{
GetNewInventoryName(); //Populate the list on reset.
}

touch_start(integer num_detected)
{
///////////
// Example Use in touch_start()
// Because Multiple Items could have been
// added between calls we work through
// the list that is retunred.
///////////

list new_inv = GetNewInventoryName();

llSay(0, "New Inventory Items:");

integer list_len = llGetListLength(new_inv);

integer counter;

for(counter = 0; counter < list_len; counter++)
{
llSay(0, llList2String(new_inv, counter));
}
}

changed(integer mask)
{
//////////////////
// Example Used in changed()
// This is much simpler, as changed()
// will be triggered each time something
// is added to the object's inventory
// resulting in only one result in the
// returned list from GetNewInventoryName()
////////////////////

if(mask & CHANGED_INVENTORY)
{
list new_inv = GetNewInventoryName();

llSay(0, "New Inventory Item:" + llList2String(new_inv, 0));
}
}

}
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-07-2008 07:03
that looks great innula. and to solve lazer's question, i suppose instead of the llSay function, it could be changed to


llSetTexture(llList2String(new_inv, 0),1); //applies it to face 1, replace with face desired, or ALL_SIDES


also, i wonder if a cycler could be added to cycle the textures when there hasn't been anything dropped for a certain amount of time