Creating A Double Sided Object Giver

I’m going to go through a little bit of scripting here, caveats apply, I have a very basic understanding of LSL, this can almost certainly be done in a more efficient manner and you use this advice at your own risk! Now on with the show. Also the scripts I have examples of don’t fit the window, so you’ll need to use the scrollbars to see it all.

One of the simple scripted tools in Second Life is a notecard giver or a freebie object giver. These are useful and the script is simple, if you want to get funky and have reports from who touched your board then it gets a tad more complicated, but the basic functionality is a simple script:

default
{
state_entry()
{
}

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

}

That’s it, just put a prim with your freebie goodies inside the object giver prim and you’re good to go. However we can build slightly on this by using both sides of the object giver prim to give a different object, to do that we can use llDetectedTouchFace, which will, as the name implies, detect which face of your prim is touched.

So let’s start by creating a new prim and then creating a new script. To do this just go to the content tab of your prim and click create new script.

Now by default when you create a new script, the Hello World script is created, we can delete that and then, as a basis for our new object giver, we will use the script at the start of this post:

An image should be here
Creating a New Script

Now we can delete all of the contents of the new script and replace it with the script at the start of this post, put an object into the contents of the prim and away we go, when we touch the prim, it gives us the object in the inventory of the prim.

However we’re going to put two objects into this prim and then you will get an object based on which side of the prim you touch. What we’ll need is a simple if statement to find out which face was touched and then give the correct object, so we’ll add something like this to our script:

        integer face = llDetectedTouchFace(0);
        if (face == 0)
        {
            llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_OBJECT, 0));
        }

        else if (face == 1)
        {
            llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_OBJECT, 1));
        }

Now this needs tweaking, for a start we have to find out which side of our prim the faces are on that we want touched, a cube has six sides, so now that we have our code, we can now find out which face is which. In order to do this, edit your prim, use the select face tool, click the face you want to find out information for and then hold down CTRL Shift Alt T:

An image should be here
Finding the side of a prim

Then look out for the messages about which side you’ve selected, you should see something like this:

 

An image should be here
Indication I’m selecting Face 3.

Therefore I know that the face I’ve selected is Face 3 and I will need to edit my script. When I select the opposite side, I am informed it’s Face 1. So now I know that I want to give out an object based on whether someone touches Face 1 or Face 3.:

   if (face == 1)
        {
            llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_OBJECT, 0));
        }

        else if (face == 3)
        {
            llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_OBJECT, 1));
        }

Now the other important part to take note of is :

INVENTORY_OBJECT, 0

The zero indicates that this is the first object in inventory, if I wanted to indicate I wanted to deal with the second object in the inventory, I’d change that zero to a 1. Ok now let’s put this together:

I have my prim, with two objects inside it, Demo Object and Second Demo Object:

An image should be here
2 Objects in Prim

Then we have the full script:

default
{
    state_entry()
    {

    }

    touch_start(integer total_number)
    {
        integer face = llDetectedTouchFace(0);
        if (face == 1)
        {
            llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_OBJECT, 0));
        }

        else if (face == 3)
        {
            llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_OBJECT, 1));
        }            
   }
}

Now if I touch one face, I’ll get Demo Object and if I touch the other side of the prim, I’ll receive Second Demo Object. Make sure you match your textures to the right object! Another quick point to note is this:

INVENTORY_OBJECT, 0

Object indicates that I’m dealing with objects, but if you want to use textures or notecards, you can use:

INVENTORY_TEXTURE, 0
INVENTORY_NOTECARD, 0

For a full list of types go here, just remember that the zero after the type indicates the first item of that type in the inventory, so for example if you wanted a texture handed out when someone touched one side and a notecard when someone touched the other side they would be as above, zero after them because they are the first of that type.

Confused? I think I am!



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow

Get the latest posts delivered to your mailbox: