LSL 101/String Concatenation

From Second Life Wiki
Jump to navigation Jump to search
← Functions That Return Values ↑̲  LSL 101  ̲↑

Thus far, the example scripts we have seen will produce the same output regardless of where in SL thay are executed. But a script can determine almost everything about the virtual environment around it, and act accordingly. As a simple case of this, lets have the script welcome us when we touch its object, using the specific name of whatever sim it is in.

<lsl> default {

    state_entry()
    {
         // Let the object's owner know the script is working
         llOwnerSay( "Congratulations! Your script has started to execute." );
    }

    touch_start( integer num_detected )
    {
         // Let the object's owner know the script is working
         llOwnerSay( "Welcome to " + llGetRegionName() + "." );
    }

} </lsl>

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.

When we say llGetRegionName returns a string, we mean that when the sim server executes the line

llOwnerSay( "Welcome to " + llGetRegionName() + "." );

it first executes the llGetRegionName function, getting back the returned string. Now let's suppose we are in Calistoga, in which case the returned string will be "Calistoga". The server then (in essence) replaces the llGetRegionName() in the above line with "Calistoga", getting

llOwnerSay( "Welcome to " + "Calistoga" + "." );

The server then concatenates the