Difference between revisions of "LSL 101/A Gentle Introduction"

From Second Life Wiki
Jump to navigation Jump to search
(edited existing text)
Line 1: Line 1:
== A Gentle Introduction to Scripting in Second Life ==
== A Gentle Introduction to Scripting in Second Life ==


{{LSL Wikibook Index}}This section of '''LSL 101: The Wikibook''' is written for the SL user who wants to script the things they build or own but who, perhaps, has no experience of any kind with programming.  If that's you, welcome!  It will also be of use to people who have experience in other programming languages and would like a gentle introduction to LSL.
{{LSL Wikibook Index}}This section of '''LSL 101: The Wikibook''' is written for the SL user who has ''no experience with computer programming''; or, for users with programming experience who would like a gentle introduction to LSL.


Since scripting is one aspect of building, we will assume that you, the reader, have rudimentary building skills.  You should, at minimum, be able to create a prim, edit it, take it in and out of your inventory, be able to do the same with a notecard, and know how to put a notecard into a prim's inventory.  That's about it.  Everything else you'll need, we'll try to cover.
This section assumes you have basic building skills, since scripting is just one aspect of building.  You should be able to create and edit a prim, then take it in and out of inventory.  You should be able to do the same with a notecard and know how to add it to a prim's inventory.


Whenever you want an object in SL to do something, to respond to a mouse click, to greet someone when they come close to it, to change its texture or colour - all the interesting things that objects do, other than just sit there - a script is needed.  Scripts take note of things that happen and are able to carry out actions in response.
If all of this sounds like you, welcome!


Scripts in SL are written in LSL (Linden Scripting Language), a simple but powerful programming language, tied closely to the SL environment.  (Simple, in this case, is used to mean it is more limited than many other popular programming languages; not necessarily that it is simpler to learn, though it is not very difficult if you are really interested to do so.)
Scripts are used to make SL objects ''do'' something.  They can detect things that happen (i.e., noticing a mouse click or the approach of an avatar); and, that script can then act in response (i.e., moving, changing appearance, greeting an avatar with a message, displaying a current stock quote).  Scripts are at work any time an object has any kind of ''behavior''.
 
In SL, scripts are written using LSL (Linden Scripting Language), a simple but powerful programming language that was created for the SL environment.  (Here, "simple" is used to suggest that LSL is ''more limited'' than other programming languages; not that it is easier to learn.  Like any other language, learning LSL requires practice.)


When you learned to speak you discovered that you needed to know not only some words (vocabulary) but also the order in which to use them (grammar). It is the same with computer languages: you have to learn the words and you have to learn the order in which to use them.  When you learned to read and write you discovered that there is also punctuation - commas, full stops (periods, if you are American), brackets, etc. - which help to clarify how different words and phrases relate to each other.  The difference between computer languages and human languages is that with human languages people can generally understand your meaning even if your pronunciation or spelling is not completely correct or your grammar is slightly wrong. Computer languages are not like that. If your spelling, punctuation or structure is even slightly wrong the computer will report an error or, at best, not do what you expected it to do.  This can be ''very'' frustrating for beginners.
When you learned to speak you discovered that you needed to know not only some words (vocabulary) but also the order in which to use them (grammar). It is the same with computer languages: you have to learn the words and you have to learn the order in which to use them.  When you learned to read and write you discovered that there is also punctuation - commas, full stops (periods, if you are American), brackets, etc. - which help to clarify how different words and phrases relate to each other.  The difference between computer languages and human languages is that with human languages people can generally understand your meaning even if your pronunciation or spelling is not completely correct or your grammar is slightly wrong. Computer languages are not like that. If your spelling, punctuation or structure is even slightly wrong the computer will report an error or, at best, not do what you expected it to do.  This can be ''very'' frustrating for beginners.

Revision as of 11:59, 21 May 2009

A Gentle Introduction to Scripting in Second Life

This section of LSL 101: The Wikibook is written for the SL user who has no experience with computer programming; or, for users with programming experience who would like a gentle introduction to LSL.

This section assumes you have basic building skills, since scripting is just one aspect of building. You should be able to create and edit a prim, then take it in and out of inventory. You should be able to do the same with a notecard and know how to add it to a prim's inventory.

If all of this sounds like you, welcome!

Scripts are used to make SL objects do something. They can detect things that happen (i.e., noticing a mouse click or the approach of an avatar); and, that script can then act in response (i.e., moving, changing appearance, greeting an avatar with a message, displaying a current stock quote). Scripts are at work any time an object has any kind of behavior.

In SL, scripts are written using LSL (Linden Scripting Language), a simple but powerful programming language that was created for the SL environment. (Here, "simple" is used to suggest that LSL is more limited than other programming languages; not that it is easier to learn. Like any other language, learning LSL requires practice.)

When you learned to speak you discovered that you needed to know not only some words (vocabulary) but also the order in which to use them (grammar). It is the same with computer languages: you have to learn the words and you have to learn the order in which to use them. When you learned to read and write you discovered that there is also punctuation - commas, full stops (periods, if you are American), brackets, etc. - which help to clarify how different words and phrases relate to each other. The difference between computer languages and human languages is that with human languages people can generally understand your meaning even if your pronunciation or spelling is not completely correct or your grammar is slightly wrong. Computer languages are not like that. If your spelling, punctuation or structure is even slightly wrong the computer will report an error or, at best, not do what you expected it to do. This can be very frustrating for beginners.

I'm sure, if you have ever attended a writing class, you were told that a story has a beginning, middle, and end. This we can call the structure of a story. In LSL the structure is very important and we will discuss that (and introduce you to some of the vocabulary, grammar and punctuation) in the next section.

You can continue with Simple Script Skeleton or The Structure of a Script.