Torn Bobbysocks
Registered User
Join date: 6 Jul 2005
Posts: 11
|
07-08-2005 13:26
Ive been pondering this for awhile. Given LSL's astounding speed, I would really like an alternative to what Ive come up with. Im trying to create a function that tells me if an item is within the object's inventory from its name. Since there isnt a llIsInInventory function I thought of using llGetInventoryKey, then saw from the wiki page that it gets flaky with items that don't have full permissions. Then, llGetInventoryCreator, but then I read that it spams the public chat channel with an error if the inventory doesn't exist. llGetInventoryPermMask does the same. My final option: a for loop, iterating over every item in inventory.
Has anyone thought of anything else?
|
FireEyes Fauna
Registered User
Join date: 26 Apr 2004
Posts: 138
|
07-08-2005 17:38
How about this. It first creates a list with the names of all items in the objects inventory. It then performs a ListFindList on it. So there's only 1 comparison to make... integer Inventory_Search(string name) { integer length = llGetInventoryNumber(INVENTORY_ALL); integer x; list inventory_names; for (x=0;x<length;x++) { inventory_names += llGetInventoryName(INVENTORY_ALL,x); } integer found = llListFindList(inventory_names,(list)name); return found; }
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
07-08-2005 18:07
Here's what I have: integer isInInventory(string name) { if (llGetInventoryKey(name) != NULL_KEY) return TRUE; integer i; integer num = llGetInventoryNumber(INVENTORY_ALL); for (i = 0; i < num; ++i) { if (llGetInventoryName(INVENTORY_ALL, i) == name) return TRUE; } return FALSE; }
==Chris
|
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
|
07-08-2005 18:20
Chris, isn't that the same as this? integer isInInventory(string name){ if (llGetInventoryKey(name) != NULL_KEY) return TRUE; return FALSE; } I mean, it wouldn't actually ever return TRUE as a result of that FOR loop, would it? 
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
07-08-2005 18:34
llGetInventoryKey returns NULL_KEY when the item does not have full permissions. Looping through the inventory with llGetInventoryName should hit every item, no matter what its permissions. ==Chris
|
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
|
07-08-2005 18:48
From: Christopher Omega llGetInventoryKey returns NULL_KEY when the item does not have full permissions. Oh, right. It's been a long day. 
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
07-08-2005 19:51
I requested a function a few months back integer llGetInventoryType(string name) with the requirement that it doesn't return a verbal error when the item doesn't exist.
I was told it was going to be in 1.7
_____________________
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
|