Difference between revisions of "Inventory Name Reader"
(created page for a simpe inventory name reader) |
m (→A shorter way: a jump really isn't needed) |
||
Line 163: | Line 163: | ||
llOwnerSay("Done Reading\n"); | llOwnerSay("Done Reading\n"); | ||
touchcounter = total_number; | |||
} | } | ||
}while(++touchcounter < total_number); | }while(++touchcounter < total_number); | ||
} | } | ||
} | } |
Latest revision as of 17:35, 19 March 2010
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Description
The following script will read out an object's inventory. The script should work fine in both mono & LSO.
Creator
Contributors
Add yourself here if you change this script.
License
This script is released into Public Domain.
Disclaimer
These programs are distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Directions
Create a prim. Fill its inventory. Place this script into that prim. Touch to read inventory.
This script will only print out the first 1024 characters of inventory.
It is more of an example for the use of the two functions getinventory and verifyinventory...this script doesn't demonstrate the best use of the two user functions...but its an example.
Inventory Name Reader.lsl
<lsl> //*********************************************************************************************************** // * // --Inventory Name Reader-- * // * //*********************************************************************************************************** // www.lsleditor.org by Alphons van der Heijden (SL: Alphons Jano) //Creator: Bobbyb30 Swashbuckler //Attribution: none //Created: April 3, 2009 //Last Modified: March 19, 2010 //Released: Wed, March 19, 2010 //License: Public Domain //Status: Fully Working/Production Ready //Version: 1.0.7 //LSLWiki: https://wiki.secondlife.com/wiki/Inventory_Name_Reader
//Name: Inventory Name Reader.lsl //Purpose: Reads the inventory of an object including the script. //Technical Overview: fairly simple to follow //Directions: Place objects into prim. Place this script into prim. Touch script to read.
//Compatible: Mono & LSL compatible //Other items required: Inventory to read //Notes: This isn't the best way to do it...more of an example ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this will verify that the inventory against the list provided integer verifyinventory(list inventory) {
//this will get the number of items in inventory integer inventorylength = llGetInventoryNumber(INVENTORY_ALL);
//check given list against actual inventory length if(llGetListLength(inventory) != inventorylength) return FALSE;
integer counter;//the counter do { if(llGetInventoryName(INVENTORY_ALL,counter) != llList2String(inventory,counter)) return FALSE;
}while(++counter < inventorylength); return TRUE;
}
//This will return a list of inventory names including this script list getinventorynames() {
integer counter;//the counter integer inventorylength = llGetInventoryNumber(INVENTORY_ALL);//this will get the number of items in inventory list listofinventorynames;//where the inventory name will be stored //string scriptname = llGetScriptName();//the name of this script...better to call it once here do { string inventoryname = llGetInventoryName(INVENTORY_ALL,counter); //if(inventoryname != scriptname)//make sure this script isn't added into the list...optional listofinventorynames += inventoryname;//add inventory name to the list }while(++counter < inventorylength); return listofinventorynames;
}
list myinventory;
default {
state_entry() { llOwnerSay("'Inventory Name Reader.lsl' released into Public Domain by Bobbyb30 Swashbuckler (C) 2010"); llOwnerSay("Touch to read off my inventory"); myinventory = getinventorynames();//get inventory } touch_start(integer total_number) { llOwnerSay("Your inventory is as follows:");
//check if inventory changed if(!verifyinventory(myinventory)) myinventory = getinventorynames();
//prepare for reading string objectname = llGetObjectName();//get object name llSetObjectName("");//Remove object name
//dump off inventory...there are better ways to do this llOwnerSay("/me " + llDumpList2String(myinventory,"\n"));
//end of reading llSetObjectName(objectname);//Restore object name } changed(integer change) { if(change & CHANGED_INVENTORY)//check if inventory changed { if(!verifyinventory(myinventory)) myinventory = getinventorynames(); } }
} </lsl>
A shorter way
This is probably a shorter/faster/more efficient way to do it <lsl> // www.lsleditor.org by Alphons van der Heijden (SL: Alphons Jano) //a short way to read off the inventory..the proper way //Bobbyb30 Swashbuckler released into Public Domain on March 19,2010 default {
touch_start(integer total_number) { integer touchcounter; do { if(llDetectedKey(touchcounter) == llGetOwner()) { llOwnerSay("Reading inventory");
//prepare for reading string objectname = llGetObjectName();//get object name llSetObjectName("");//Remove object name integer counter; integer inventorylength = llGetInventoryNumber(INVENTORY_ALL); do { llOwnerSay("/me " + llGetInventoryName(INVENTORY_ALL,counter)); }while(++counter < inventorylength);
//end of reading llSetObjectName(objectname);//Restore object name llOwnerSay("Done Reading\n"); touchcounter = total_number; } }while(++touchcounter < total_number); }
} </lsl>
Other
If you find this script of use, please do let me know=D.