LSL 101/Functions

From Second Life Wiki
Jump to navigation Jump to search
← Variable Initialization ↑̲  LSL 101  ̲↑ Functions That Return a Value →


Surprise! We've been using functions all through this Wikibook! Everything that starts llSomeOddBunchOfRedText is actually a Linden Lab (hence the two lower-case "ll"s at the beginning) ready made function.

The most common ones include llSay, llOwnerSay, llSetText, llTargetOmega, and llParticleSystem and there is a complete list of them here on the LSL Functions page of this Wiki.

How functions are documented on this Wiki

Each function is shown at the top of the page with its parameters and data types, like this:

Function: llSay( integer channel, string message );

What this is telling you is that this is a Function... named *llSay* which will to use a channel to say a message when triggered.

default
{
    state_entry()
    {
       llSay(0,"Hello Avid Scriptor!"); 

       // the wiki shows us:-  
       //      llSay(integer channel, string message)
       // In this example:- 
       //      the channel is zero, and the message is "Hello, Avid Scriptor!"
    }
}

Having come this far in the series you know that's exactly the same thing as writing a script which looks like this:

integer channel = 0;
string message = "Hello, Avid Scriptor!";


default
{
    state_entry()
    {
         llSay(channel, message);
    }
}

For the cut-and-paste enthusiast, please notice that the terminal semi-colon is NOT at the end of the function call on the Wiki (as the ; is not a part of the function call itself). You will need to add a semi-colon at the end of your statement.

Below the function explanation, there are distinct sections for different types of information, the sections on each page may include:

  1. Description - Contains a basic description
  2. Newbie Notes - Contains a description and examples intended for new users - very few articles have this section, we haven't found anyone to write them.
  3. Examples - Contains examples of how to use the function.
  4. Caveats - Contains a list of edge cases (where things may break) and what happens when things break. This is the fine print which if you don't read you will likely get a nasty surprise later.
  5. (Important) Issues - A list of LSL bugs (and feature requests) reported on JIRA. The list is likely incomplete but should give you a taste as to what might be wrong with the function.
  6. Notes - Much more detailed description of edge cases and how to use the function. Examples will show you how, but Notes will describe when, why and more of the how.
  7. See Also - Links to other articles, functions, events etc.
  8. Specification - For when Caveats isn't enough and Notes is too general.

Caveats and Specification aren't always geared towards new users, the documentation also servers as reference and refresher material for advanced users. It's best to come back to these sections once you have an idea of what the function does. The layout is very much a balancing act of divergent interests.

There are some other sections, Deep Notes for example contains everything that really isn't all that important to the functionality. Typically technical implementation notes, only useful when discussing changing the implementation.

How to get started using Functions

Go to the wiki entry for the function you wish to use, perhaps easiest is to type "LSL rotate" or "LSL Hover Text" in google or other search engine and follow the links into the wiki. The reason for that is - when you are starting - the commands are confusing and using the in-wiki search requires not only accuracy but remembering to Capitalize the first letter in LlSay for example, which is not how it is typed in scripts & only intuitive if you understand it's default wiki terminology - they can't change it, as much as everyone wishes they could.

Save scripts & script snippets you play with in a folder in your inventory. When you find something that works, name it so you can find it, date it and keep it. Also, keep your first script. It'll be a memento someday.

Easy Reference for Wiki Links

The LSL Portal is one of the best single source link pages for everything to do with LSL scripting. Follow the links to in-depth discussions on various LSL language topics.


To continue this tutorial, go back to Variable Initialization or proceed onward to Functions That Return a Value.