Difference between revisions of "LSL 101/Functions"

From Second Life Wiki
Jump to navigation Jump to search
m (created page with data from old page, will save, then add more & edit.)
m (expand functions)
Line 10: Line 10:
==How functions are documented on 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.
Each function is shown at the top of the page with its parameters and data types, like this:
<lsl>
Function: llSay( integer channel, string message );
</lsl>
 
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.  


Here's a familiar example in this snippet
<lsl>
<lsl>
Function: llSay( integer channel, string msg );
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!"
    }
}
</lsl>
</lsl>


What this is telling you is that this is a Function... named *llSay* which is expecting to use a channel to say a message.
Having come this far in the series you know that's exactly the same thing as writing a script which looks like this:


<lsl>
<lsl>
integer channel = 0;
string message = "Hello, Avid Scriptor!";
default
default
{
{
     state_entry
     state_entry()
     {
     {
      llSay(0,"Hello Avid Scriptor!");  // shows the (integer channel, string message)
        llSay(channel, message);
     }
     }
}
}
</lsl>
</lsl>
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.  You have to add it every time. 


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

Revision as of 22:45, 7 July 2012

← Variables ↑̲  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: <lsl> Function: llSay( integer channel, string message ); </lsl>

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.

<lsl> 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!"
   }

} </lsl>

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

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


default {

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

} </lsl>

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. You have to add it every time.

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.

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