LSL 101/Functions That Return a Value

From Second Life Wiki
Jump to navigation Jump to search
← Compile Time Errors ↑̲  LSL 101  ̲↑ String Concatenation →

The built-in functions we've seen so far, llSay and llOwnerSay, act as commands, causing something to happen in SL. But other built-in functions are used to retrieve information from SL and make it available to the script. In this case, we say that the function returns the information.

The built-in function llGetRegionName is an example of this. When executed, it returns the name of whatever sim the script is executing in. If the script is running in Ganymede, for example, executing llGetRegionName would return the string "Ganymede".

Here's how that would work in a sript. <lsl> default {

    state_entry()
    {
         // Announce the name of the current region
         llOwnerSay( llGetRegionName() );
    }

} </lsl>

Notice that llRegionSay does not take any parameters, but it still has to be followed by a pair of parentheses. It is 'not' followed by a semicolon, because it is not, by itself, a statement.

When the SL sim server executes the line

llOwnerSay( llGetRegionName() );

it first executes the llGetRegionName function and (in essence) replaces llGetRegionName() with the string that is returned. This results in something like

llOwnerSay( "Ganymede" );

which chats the string "Ganymede" to the object's owner.

In the touch_start event handler, we see llGetRegionName(), which looks like a built-in function with no parameters, which is exactly what it is. But it doesn't stand by itself on a line with a semicolon after it, as did the previous built-in functions we've seen. That's because unlike llSay or llOwnerSay, which cause something to happen in SL, llGetRegionName retrieves information from SL (in this case, a string containing the name of the current region) and returns it to the script.