Basic scripting tutorials

From The SchomEmunity Wiki
Jump to: navigation, search

The scripting language in the SL world is called LSL (the Linden Scripting Language) and is used to make objects do many different things such as make objects speak

LSL is a cross between Java and C/C++ so any experience, though not essential, is useful; even so, the code is fairly different and so some learning is needed even if you have experiance programming in those

The basics

This may be hard to learn but, once you know how, it's a basic thing you will remember for all scirpts . Its worth looking at an example; to get a simple one, create any object then, on the 'Content' tab (on the edit screen), click 'New Script'.

Part 1 - Starting out

All scripts start require a 'default state' (started with 'default {' and ended with a '}'; the brackets can be on separate lines to 'default', and there can be other pairs of {}s within this as long as they are balanced (*))

Part 2 - Events

Events are functions that are called when certain things happen. Here are the two which are used in the default script:

  • state_entry() - called when an avatar comes near or the script is reset (among others)
  • touch_start(integer total_number) - called when an avatar (or multiple avatars at once - the total_number argument (**) indicates how many) touches the object

Events must be placed within a state, normally the 'default state'

Part 3 - Statements

You will need to tell SL what to do when events happen. To do this, you will need to put the event name, as shown above, followed by an open brace (a '{'), then some statements telling it what to do, then a closing brace (a '}')

Statements are things like these:

  • llSay(0, "Hello, world!");
  • i = 1;
  • s = "Hi!";

Each function (***) has a specific number of arguments; you must put in exactly this many and put the correct types - the following are invalid:

  • llSay("Hello, world!", 0); - incorrect argument types
  • llSay(0); - not enough arguments

Every statement must be finished with a semicolon!

Part 4 - Repeat

If your script will handle more than one event, you simply need to add the others and tell the script how to act when those happen.


* balanced (brackets) - pairs of matching brackets - for example, '()' and '(())' are balanced, but '(()' and '())' are not.

** argument - A value given to a function (***) - for example, in 'llSay(0, "Hi!")', the 0 and the "Hi!" are arguments.

*** function - A group of one or more statements which is nicely packed so you can use a single statement to run them - for example, 'llDie()' is a function which causes the object containing the script to be deleted