Basic scripting tutorials

From The Schommunity Wiki

Jump to: navigation, search

http://img150.imageshack.us/img150/4093/scriptingthf3.png

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

Contents

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:

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:

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

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.

Glossary

* 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

Personal tools
Namespaces
Variants
Actions
wiki navigation
schome website
Virtual worlds
Useful stuff
Toolbox