Difference between revisions of "LSL 101/Strings and Simple Output"

From Second Life Wiki
Jump to navigation Jump to search
m (LSL 101/Simplest Output moved to LSL 101/Strings and Simple Output: More descriptive title)
m (<lsl> tag to <source>)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:LSL 101]]
[[Category:LSL 101]]
{{NavNextPrev|prev=Comments, White-space and Formatting|next=The touch_start Event}}
{{NavNextPrev|prev=Variables|next=String Concatenation}}
 
{{LSL Wikibook Index}}
Here's our sample program, with a line added so that the script actually does something.
Here's our sample program, with a line added so that the script actually does something.


<lsl>
<source lang="lsl2">
default
default
{
{
Line 13: Line 13:
     }
     }
}
}
</lsl>
</source>


The line that starts with llOwnerSay is a '''statement''' that instructs the object containing the script to chat a text message that will only be seen by the object's owner.  Since you will usually be scripting objects you own, this will generally be you.  This is a convenient way to get information about what your script is doing, without spamming text chat to everyone around you. But if you have an occasion (and permission) to script someone else's object, you would want to use one of the other communication statements, which we'll discuss in due time.
The line that starts with llOwnerSay is a '''statement''' that instructs the object containing the script to chat a text message that will only be seen by the object's owner.  Since you will usually be scripting objects you own, this will generally be you.  This is a convenient way to get information about what your script is doing, without spamming text chat to everyone around you. But if you have an occasion (and permission) to script someone else's object, you would want to use one of the other communication statements, which we'll discuss in due time.
Line 21: Line 21:
The next set of punctuation marks to observe is the pair of double quote marks surrounding the text "Congratulations! Your script has started to execute.".  Double quote marks always come in pairs, and they, together with whatever characters come between them, are called a '''string'''.  Strings can contain any printable characters (although a few require a special trick).  The most important use of strings is to display text in SL.  The actual content of a string does not have any effect on how your script runs, unless you specifically write code to examine the string and take different actions depending on what the content is.
The next set of punctuation marks to observe is the pair of double quote marks surrounding the text "Congratulations! Your script has started to execute.".  Double quote marks always come in pairs, and they, together with whatever characters come between them, are called a '''string'''.  Strings can contain any printable characters (although a few require a special trick).  The most important use of strings is to display text in SL.  The actual content of a string does not have any effect on how your script runs, unless you specifically write code to examine the string and take different actions depending on what the content is.


The final set of punctuation, the parentheses, are associated with the name llOwnerSay.  llOwnerSay is our first example of a '''built-in function'''.  Built-in functions always start with the lower case "ll" (for Linden Labs).  A built-in function will typically tell the Second Life server to do something (like display text or change the position of a prim) or make a query about the SL world (such as what avatars are nearby).  There are hundreds of different built-in functions.  Once you get the basics of scripting down, most of your learning time will be spent finding out which built-in functions do what you want to do, along with the nitty-gritty of how they work.  Fortunately, most scripts need only a handful of different functions, so you won't need to learn hundreds, or even tens, of built-in functions before you can write simple scripts.
The final set of punctuation, the parentheses, are associated with the name llOwnerSay.  llOwnerSay is our first example of a '''built-in function'''.  Built-in functions always start with the lower case "ll" (for Linden Lab).  A built-in function will typically tell the Second Life server to do something (like display text or change the position of a prim) or make a query about the SL world (such as what avatars are nearby).  There are hundreds of different built-in functions.  Once you get the basics of scripting down, most of your learning time will be spent finding out which built-in functions do what you want to do, along with the nitty-gritty of how they work.  Fortunately, most scripts need only a handful of different functions, so you won't need to learn hundreds, or even tens, of built-in functions before you can write simple scripts.


The general pattern for using a built-in function is  
The general pattern for using a built-in function is  
Line 29: Line 29:
where llXXX refers to any built-in function and the number of parameters is different for different built-in functions.  For example, llOwnerSay always takes one parameter, and that parameter has to be a string.  Commas separate parameters, so if there is only one parameter, no comma is needed (or allowed).
where llXXX refers to any built-in function and the number of parameters is different for different built-in functions.  For example, llOwnerSay always takes one parameter, and that parameter has to be a string.  Commas separate parameters, so if there is only one parameter, no comma is needed (or allowed).


Now that we know how to make something visible happen in SL, let's add a second [[LSL 101/The touch_start Event|event handler]].
'''Continuie this tutorial by going onward to [[LSL 101/String Concatenation | String Concatenation]] or go back to [[LSL 101/Variables | Variables]].'''

Latest revision as of 13:46, 24 January 2015

← Variables ↑̲  LSL 101  ̲↑ String Concatenation →

Here's our sample program, with a line added so that the script actually does something.

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

The line that starts with llOwnerSay is a statement that instructs the object containing the script to chat a text message that will only be seen by the object's owner. Since you will usually be scripting objects you own, this will generally be you. This is a convenient way to get information about what your script is doing, without spamming text chat to everyone around you. But if you have an occasion (and permission) to script someone else's object, you would want to use one of the other communication statements, which we'll discuss in due time.

Take a look at the punctuation in this line. Every statement in LSL must end with a semicolon. This is probably the easiest punctuation mark to overlook, but if it isn't there, your script isn't acceptable. Furthermore, the error message you get will probably puzzle you, because it will tell you the error is on the line following the missing semicolon, and it won't tell you that it is a semicolon that is missing. So work especially hard at remembering your semicolons.

The next set of punctuation marks to observe is the pair of double quote marks surrounding the text "Congratulations! Your script has started to execute.". Double quote marks always come in pairs, and they, together with whatever characters come between them, are called a string. Strings can contain any printable characters (although a few require a special trick). The most important use of strings is to display text in SL. The actual content of a string does not have any effect on how your script runs, unless you specifically write code to examine the string and take different actions depending on what the content is.

The final set of punctuation, the parentheses, are associated with the name llOwnerSay. llOwnerSay is our first example of a built-in function. Built-in functions always start with the lower case "ll" (for Linden Lab). A built-in function will typically tell the Second Life server to do something (like display text or change the position of a prim) or make a query about the SL world (such as what avatars are nearby). There are hundreds of different built-in functions. Once you get the basics of scripting down, most of your learning time will be spent finding out which built-in functions do what you want to do, along with the nitty-gritty of how they work. Fortunately, most scripts need only a handful of different functions, so you won't need to learn hundreds, or even tens, of built-in functions before you can write simple scripts.

The general pattern for using a built-in function is

   llXXX( parameter1, paramter2, ... )

where llXXX refers to any built-in function and the number of parameters is different for different built-in functions. For example, llOwnerSay always takes one parameter, and that parameter has to be a string. Commas separate parameters, so if there is only one parameter, no comma is needed (or allowed).

Continuie this tutorial by going onward to String Concatenation or go back to Variables.