CHAPTER 1
CHAPTER 2
CHAPTER 3
CHAPTER 4
CHAPTER 5
CHAPTER 6
CHAPTER 7
CHAPTER 9
CHAPTER 10
CHAPTER 11
CHAPTER 12
CHAPTER 13
CHAPTER 14
CHAPTER 15
APPENDIC
E
S
189
dataserver(key requestID, string data) {
vector regionCoords = (vector)data;
llOwnerSay("Landmark is at " + (string)regionCoords );
}
}
TABLE 8.2: INVENTORY INFORMATION FUNCTIONS
FUNCTION BEHAVIOR
integer llGetInventoryNumber(integer type)
Returns an integer that is the number of items of a given
type in the prim's inventory.
string llGetInventoryName(integer type,
integer number)
Returns a string that is the name of the inventory item
number of type. Returns an empty string if nothing is found.
integer llGetInventoryType(string name)
Returns an integer that is the type of the inventory item
name. Using the item's key will not work.
key llGetInventoryCreator(string name)
Returns a key of the creator of the inventory name. Using
the item's key will not work.
key llGetInventoryKey(string name)
Returns a key that is the UUID of the inventory name. If
you do not have full permissions on the inventory object,
this returns NULL_KEY.
key llRequestInventoryData(string name)
Returns to the dataserver query a key that is a unique
identifier. A dataserver() event will be triggered when
the data is ready. Currently valid only for landmarks.
GIVING INVENTORY
Containers are objects that hold on to things until they are needed in the environment or in interactions
with residents. Containers that give out landmarks and notecards are prime examples of interaction tools
you will find necessary every day in Second Life. When you've given away singleton objects a couple of
times, you will realize how convenient it is to give a long list of items at one time.
PLEASE TAKE A NOTE(CARD)
Listing 8.2 shows a simple notecard giver. At SYW HQ, it is embodied in a fountain that offers each sensed
avatar a notecard containing a horoscope. The core is a simple one-liner that offers each detected avatar
the first (i.e., zeroth) notecard item found in inventory:
llGiveInventory(llDetectedKey(i), llGetInventoryName(INVENTORY_NOTECARD, 0));
Listing 8.2: Notecard Giver
integer MEMORY_LENGTH = 25;
list gAvatars;
add_avatar(string name) {
gAvatars += name;
if (llGetListLength(gAvatars) > MEMORY_LENGTH) {
gAvatars = llDeleteSubList(gAvatars,0,0);
}
}
190
INVENTORY
PROPERTIES
GIVING
INVENTORY
TAKING
INVENTORY
PERM ISSIONS
SUMMARY
default {
state_entry() {
llVolumeDetect(TRUE);
}
touch_start(integer num) { // report who received notecard
if (llDetectedKey(0) == llGetOwner()){
integer i;
integer numAvs = llGetListLength(gAvatars);
for (i=0; i<numAvs; i++){
llOwnerSay("Gave a note to " + llList2String(gAvatars, i));
}
gAvatars = [];
}
}
collision_start(integer total_number) {
integer i;
for (i=0; i<total_number; i++) {
if (llListFindList(gAvatars,[llDetectedName(i)]) == -1) {
// Pick out the first NOTECARD and offer it
llGiveInventory(llDetectedKey(i),
llGetInventoryName(INVENTORY_NOTECARD,0));
add_avatar(llDetectedName(i));
}
}
}
}
Figure 8.1 shows a resident walking up to the fountain, and the subsequent interaction. Note that, as
with the memory greeter from Listing 5.8 in Chapter 5, "Sensing the World," the fountain keeps a list of
the latest 25 residents who have received a notecard, and rolls off the oldest whenever it adds the newest
avatar in the add_avatar() function.
Figure 8.1: A
fountain offers
a notecard to
passersby.
CHAPTER 1
CHAPTER 2
CHAPTER 3
CHAPTER 4
CHAPTER 5
CHAPTER 6
CHAPTER 7
CHAPTER 9
CHAPTER 10
CHAPTER 11
CHAPTER 12
CHAPTER 13
CHAPTER 14
CHAPTER 15
APPENDIC
E
S
191
Whenever the owner touches the fountain, it reports the latest residents to have approached, and
then (optionally) clears the list altogether, just like the reporting greeter of Listing 5.9 in Chapter 5. You
may or may not want to determine whether a resident has previously seen a notecard, but you can test for
the name in the gAvatars list. You may also want to offer the avatar the notecard when they touch the
fountain, just in case they accidentally clicked Ignore on the first menu.
llGiveInventory(key recipient, string inventory)
Offers an item from an objects inventory. There is no way to tell if an offer is accepted, refused, or
silently failed. An offer to an avatar delays the script by three seconds; an offer to another object is not
delayed at all.
recipientThe key of a potential recipient (an avatar or another object). Avatars have the
opportunity to refuse the offer. Offers to objects not in the same sim will fail
silently.
inventoryThe name of an item from the objects inventory.
DEFINITION
Looking at Figure 8.2, you can see the kind of prescient, insightful advice this particular notecard
giver dispenses. Some residents will find value in receiving fresh astrological guidance in-world every
day. However, remember that the notecard giver's advice is static, and this makes it weak for a usage
where data freshness might be important for drawing repeat visitors. This too can be remedied by
talking to an external web server that creates a custom notecard, as covered in Chapter 12, "Reaching
outside Second Life."
Figure 8.2: Your
fortune in a
notecard!

Get Scripting Your World: The Official Guide to Second Life® Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.