Difference between revisions of "User talk:Prajna Vella"

From Second Life Wiki
Jump to navigation Jump to search
m
Line 1: Line 1:
Please excuse the mess, I am just having a play here to get used to wiki editing, so that I might be able to present useful information (particularly with regard to LSL scripting and sculpties) in a clear and convenient manner.
// Give object contents in a folder to AV on touch - by Prajna Vella
[[User:Prajna Vella|Prajna Vella]] 12:34, 4 May 2009 (UTC)
//
 
// This script can be put in a 'giver' object along with the items you want to give to
Here is a short script to test the LSL layout:
// anyone who touches the object.  If you want to add an item, just add it to the
// object's contents; the script will notice the change and update the list.
//
// The script will not give any no-transfer items (because it can't, just as you can't)
// and it will warn you if you put no-copy items in it (since once it has given a copy
// of the item it won't have another copy to give to someone else).


<lsl>
// Give object contents in a folder to AV on touch - by Prajna Vella
string version = "1.0"; // the script version number
string version = "1.0"; // the script version number
string folder = "Ephemera - Gifts"; // the name of the folder we will give to the AV that touches the object
string folder = "Ephemera - Gifts"; // the name of the folder we will give to the AV that touches the object
string title = "Gifts"; // the floating title for the giver object
string title = "Gifts"; // the floating title for the giver object
list contents; // the list of items we will put in the folder
list contents; // the list of items we will put in the folder
// check we can give the item and if so add it to the list
// this could have been included in the getList() function but the script is
// much more readable if it is done here.
addItem(string item) {
// get the permissions the object owner has for this item
integer ownerPerms = llGetInventoryPermMask(item, MASK_OWNER);
// only add items the owner has permission to copy and transfer
if ((ownerPerms & (PERM_COPY | PERM_TRANSFER)) == (PERM_COPY | PERM_TRANSFER))
// add the item to the list
contents += item;
else
llOwnerSay("Couldn't add '" + item + "' because you must have transfer and copy permissions.");
}


// get the list of the items we will give
// get the list of the items we will give
getList() {
getList() {
// empty the list of items
contents = [];
// how many items are there in the contents?
// how many items are there in the contents?
integer item = llGetInventoryNumber(INVENTORY_ALL);
integer item = llGetInventoryNumber(INVENTORY_ALL);
Line 20: Line 39:
while (item) {
while (item) {
// this line gets the item name but first decrements the item counter
// this line gets the item name but first decrements the item counter
// it is very efficient and takes care of the fact items are numbered starting with 0
// it is very efficient and takes care of the fact itemes are numbered starting with 0
string thisItem = llGetInventoryName(INVENTORY_ALL, --n);
string thisItem = llGetInventoryName(INVENTORY_ALL, --item);
// we need to check we don't give a copy of this script
// we need to check we don't give a copy of this script
if (thisItem != thisScript)
if (thisItem != thisScript)
contents += thisItem;
addItem(thisItem);
}
}
}
}
Line 31: Line 50:
config() {
config() {
// tell the owner what is happening and get the list of items to give
// tell the owner what is happening and get the list of items to give
llOwnerSay("Version " + version);
llOwnerSay("Configuring...");
llOwnerSay("Configuring...");
getList();
getList();
llOwnerSay("Version " + version);
llOwnerSay("Ready to give folder " + folder);
llOwnerSay("Ready to give folder " + folder);
llOwnerSay("Containing: " + llList2CSV(contents));
llOwnerSay("Containing: " + llList2CSV(contents));
Line 52: Line 71:
while (count) {
while (count) {
// we find out the UUID key of the AV that touched
// we find out the UUID key of the AV that touched
key id = llDetectedKey(--n);
key id = llDetectedKey(--count);
// and give them the folder
// and give them the folder
llGiveInventoryList(id, folder, contents);
llGiveInventoryList(id, folder, contents);
Line 65: Line 84:
}
}
}
}
</lsl>

Revision as of 09:18, 4 May 2009

// Give object contents in a folder to AV on touch - by Prajna Vella // // This script can be put in a 'giver' object along with the items you want to give to // anyone who touches the object. If you want to add an item, just add it to the // object's contents; the script will notice the change and update the list. // // The script will not give any no-transfer items (because it can't, just as you can't) // and it will warn you if you put no-copy items in it (since once it has given a copy // of the item it won't have another copy to give to someone else).

string version = "1.0"; // the script version number string folder = "Ephemera - Gifts"; // the name of the folder we will give to the AV that touches the object string title = "Gifts"; // the floating title for the giver object list contents; // the list of items we will put in the folder

// check we can give the item and if so add it to the list // this could have been included in the getList() function but the script is // much more readable if it is done here. addItem(string item) { // get the permissions the object owner has for this item integer ownerPerms = llGetInventoryPermMask(item, MASK_OWNER); // only add items the owner has permission to copy and transfer if ((ownerPerms & (PERM_COPY | PERM_TRANSFER)) == (PERM_COPY | PERM_TRANSFER)) // add the item to the list contents += item; else llOwnerSay("Couldn't add '" + item + "' because you must have transfer and copy permissions."); }

// get the list of the items we will give getList() { // empty the list of items contents = []; // how many items are there in the contents? integer item = llGetInventoryNumber(INVENTORY_ALL); // we find out the name of this script here so we only have to do it once string thisScript = llGetScriptName(); // this efficiently refers to the current item and will loop until we have reached item 0 while (item) { // this line gets the item name but first decrements the item counter // it is very efficient and takes care of the fact itemes are numbered starting with 0 string thisItem = llGetInventoryName(INVENTORY_ALL, --item); // we need to check we don't give a copy of this script if (thisItem != thisScript) addItem(thisItem); } }

// we do this as a user defined function so it can be called from both state_entry() and changed() events config() { // tell the owner what is happening and get the list of items to give llOwnerSay("Version " + version); llOwnerSay("Configuring..."); getList(); llOwnerSay("Ready to give folder " + folder); llOwnerSay("Containing: " + llList2CSV(contents)); // set the floating text on the giver llSetText(title, <1.0,1.0,1.0>, 1.0); }

default { // when the script starts running state_entry() { config(); }

// when someone touches the object touch_start(integer count) { // count is how many people touched the object while (count) { // we find out the UUID key of the AV that touched key id = llDetectedKey(--count); // and give them the folder llGiveInventoryList(id, folder, contents); } }

// when the contents of the object is changed changed(integer change) { if (change && CHANGED_INVENTORY) // we get the list of items again config(); } }