Monday, August 20, 2007

Scripting lesson 1 - Notecard giver

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


You can place this script into any prim. As soon as somebody touches the prim, a notecard will be given to the person who touched it. The notecard needs to be also inside the prim for this.

Now lets look into the details, line by line:

key user;
this is the declaration of a variable. The type of the variable is "key" and the name is "user". Note, that nearly all lines in LSL end with a ;


default
{
......
}

All default events will find their place in between the brackets { ...}, introduced by the word "default".

touch_start(integer total_number)
{
.....
}
This is the "touch-event". It always occurs when someone touches the prim. Actions between the { } are executed then.

user=llDetectedKey(0);
Each Resident has a Userkey. This function detects the Userkey of the avatar who touched the prim.

llGiveInventory(....);
Gives the Inventgoryitem specified in the function. When talking about "Inventory", that refers to the inventgory of the prim, not your personal inventory.

llGetInventoryName(....)
Get the name of the item in the inventory, which is supposed to be given to the user.

For questions about the details on each function, read on at http://lslwiki.net

No comments: