Category:LSL User-Defined Functions

User-Defined Functions

This category contains custom pre-defined function contributions from the LSL community to extend the abilities of LSL. To add a wiki page to this category, include a link to this page. You may use the Template:LSL_Function (with "mode" set to user) to create the page to be added here.

Go to the Functions page to view the built-in functions.

About User-Defined Functions

LSL allows user-defined functions which will help keep scripts compact and readable, and allow code reuse. The LSL Style Guide suggests that user-defined functions should be placed before the default state definition and after user-defined variables.

The definitions are as follows:

<return_type> function_name([<parameter1_type> parameter1[, <parameter2_type> parameter2[, ...]]])
{
  function_statements;

  ...

  return value_of_return_type;
}

Examples

// example with void return type:

let_prim_say_something_and_include_owner_info(string message)
{
    key ownerKey = llGetOwner();
    string ownerName = llKey2Name(ownerKey);

    llSay(PUBLIC_CHANNEL, "/me (owned by " + ownerName + "): " + message);
}

default
{
    state_entry()
    {
        let_prim_say_something_and_include_owner_info("Hello world!");
    }
}
// example with integer return type (actually it's a boolean)

integer is_sun_up()
{
    vector sunDirection = llGetSunDirection();

    if (sunDirection.z < 0.0)
        return FALSE;

    // else
        return TRUE;
}

default
{
    state_entry()
    {
        if (is_sun_up())
            llSay(PUBLIC_CHANNEL, "Good day!");
        else
            llSay(PUBLIC_CHANNEL, "Good night!");
    }
}

Below is a list of functions on this wiki that have been included in this category:

Pages in category