LSL 101/Functions
← 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:
- Description - Contains a basic description
- 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.
- Examples - Contains examples of how to use the function.
- 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.
- (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.
- 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.
- See Also - Links to other articles, functions, events etc.
- 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.