PASTE NAVIGATION MENU CODE

Wednesday 27 June 2012

Task 3: Using Note Cards

| | with 0 comments |
Note cards are to Second Life what postcards are to the real world. Note cards are used to describe a location within section life including an in-world URL which can be used to teleport to locations within the Second Life universe. Note cards can contain many other things. Players can attach objects to notecards and give them to each other. Notecards can also have embedded text, video and audio - making them very versatile. 

In this section, a notecard giver will be created. For now, the functionality will be implemented as a second button on the virtual kiosk.



When the player touches the button, a notification will be displayed asking the user whether to accept the note card which has been given.



If the player accepts the note card, it will be added to their inventory and immediately displayed.



In this sample note card, the player is greeted with some text and then given a copy of the kiosk we are working on. The user can then add the kiosk to their inventory.

To achieve this, two items are required. First, a note card has to be created and added to the inventory of the button. To do this, go to your inventory, right-click on "Calling Cards" and select "New note card". After naming the note, double-click on it to start typing text.



To add an object to the note, simply find it in your inventory and drag it inside the note. The item dragged in the note must have the unrestricted "next owner" permission, or it may not be owned by other players. To set this permission, right-click the item you want to attach in the inventory and grant all permissions to the next owner group.



Once this is done, the object can be transferred to the note card. With the note card created, it must now be dragged into the inventory of the button. Right-click the button and select "build", then go to the contents tab. Drag the note card from your inventory to the contents area.



The last piece of the puzzle is to create a script which gives the notecard to the user when the object is touched.

default {
    touch_start(integer total_number) {
        llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_NOTECARD, 0));
    }
}

As can be seen, the script is very simply. The llGetInventoryName function is used to get the name of the first item (number 0) matching the INVENTORY_NOTECARD description within the object inventory. This item is then given to the owner by using the llGiveInventory function, which additionally needs the name of the player the item is going to be given to, which can be obtained using the function llDetectedKey(0). All the rest is handled automatically by Second Life.

Expanding the concept: A post box

Expanding on the concept above, a post box was built. This allows players to store notecards in an item and then retrieve them at a later date. First, a post box-like shape was added to the side of the kiosk.



When the user right-clicks the post box, they can select "open". This will show the user the inventory of the post box - but will only show items owned by the user.



Once opened, items can be dragged to the post box, in this case, "My New Note".



At a later date, when the post box is clicked, the user's items are returned.





The code for the post box is shown below.

default{
    state_entry(){
         llAllowInventoryDrop(TRUE);
    }
    touch_start(integer total_number){
        llOwnerSay("Giving you your items...");
        key owner = llGetOwner();    

        integer i=0;
        if (llDetectedKey(0) == owner) {
            for (i=0; i<llGetInventoryNumber(INVENTORY_NOTECARD); i++) {
                llGiveInventory(llDetectedKey(0), llGetInventoryName(INVENTORY_NOTECARD, i));
            }
        }
    }
}

When the post box is initialized, the llAllowInventoryDrop function is used to allow the player to drop items in the inventory of the post box. When the post box is touched (touch_start()) A loop is used which goes through every note card in the inventory. Each note card's owner is checked, and if the owner of the card matches with the current player, the item is offered to the player.

Post a Comment

Please enter your comments here..

0 comments: