Intermediate scripting

From The SchomEmunity Wiki
Jump to: navigation, search

The Basics

There is a basic intoduction into scripting a simple cafe stool Second_Life_scripting. But where do you go from there? This is where!

Background

The scripting language in SL is called Linden Scripting Language (hereafter LSL), it is rather similar to C++ and Java. By scripting they essentially mean programming (or giving a set of instructions to).

To make a script you make a prim, create a new script in it, then open it up and start editing it. The very first script you will see is the classic "Hello, Avatar!" script. I'll talk you through this.

default
{
    state_entry()
    {
        llSay(0, "Hello, Avatar!");
    }

    touch_start(integer total_number)
    {
        llSay(0, "Touched.");
    }
}

For now you can ignore the 'default' statement. The 'state_entry()' part tells SL that when this script is started to go straight to this bit and do what ever is in the curly brackets {} (yes, that is the technical name for them!). Here we see that the only thing in the curly brackets is the llSay function. This is one of LSL built in functions that essentially make everything work in SL, ALL of these functions have a 'll' at the start. This one takes two arguements (arguments are the bits in the normal brackets, like these ones). In this case it is saying say 'Hello, Avatar!' to the chat channel 0, i.e. the normal chat channel.

Further down we come to the 'touch_start(integer total_number)' part. This is an important statement as it is the first time we see an 'event'. LSL is an event driven language, now that isn't as scary as it sounds. What it means is that the script will sit there doing nothing until an 'event' happens, in this case the event is for someone to touch the prim. When that happens the script immediately jumps to the 'touch_start' event handler (thing that handles an event) and does the bit inside the curly brackets. In this case it says "Touched".

I will attempt to explain everything as time goes on, but if you have any particular questions post them here and I will try to incorporate them into this.--Olly 20:55, 20 May 2007 (BST)