LSL 101/Variables

From Second Life Wiki
Jump to navigation Jump to search
← String Concatenation ↑̲  LSL 101  ̲↑

In our previous example, each time the touch_start event handler is invoked we ask the server for the name of the region using llGetRegionName. If we know the object with the script isn't going to be moving between regions, we might like to get the region name from the server just once, and then reuse the name each time the object is clicked on. To do that, we need to use a variable to store the region name.

Here's a script that asks for the sim's name when the script is initialized, stored the name in a variable we have named RegionName, and uses that as the source for the name each time it is needed.

<lsl>string RegionName;

default {

    state_entry()
    {
         // Store the name of the current sim for later use
         RegionName = llGetRegionName();
    }

    touch_start( integer num_detected )
    {
         // Announce the region where the script is running
         llOwnerSay( "Welcome to " + RegionName  + "." );
    }

}</lsl>