Difference between revisions of "LSL 101/Variables"

From Second Life Wiki
Jump to navigation Jump to search
(New page: Category:LSL 101 {{NavNextPrev|prev=String Concatenation|next=}})
 
Line 1: Line 1:
[[Category:LSL 101]]
[[Category:LSL 101]]
{{NavNextPrev|prev=String Concatenation|next=}}
{{NavNextPrev|prev=String Concatenation|next=}}
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>

Revision as of 20:03, 21 May 2009

← 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>