Advertisement
itoibo

temp

Jan 10th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.08 KB | None | 0 0
  1. ~
  2. NextPicture
  3. ~
  4. ~Let's begin our lesson. We are going to go over the structure of a script and some key words you should know.. Then we are going to have some fun with a script!
  5.  
  6. ~Please zoom in on a display screen and follow along in your local chat.
  7. ~
  8. NextPicture
  9.  
  10.  
  11. ~
  12. ~SCRIPT STRUCTURE~
  13. ~
  14. ~REMEMBER THE FOLLOWING STRUCTURE:
  15.  
  16. ~
  17. ~SCRIPTS ~ contain
  18. ~ STATES ~ which contain
  19. ~ EVENTS ~ which contain
  20. ~ FUNCTIONS;
  21. ~
  22. ~Read that a few times and commit it to memory. It is the most important thing to remember as a new script writer.
  23. ~
  24. ~NextPicture
  25.  
  26.  
  27.  
  28. ~
  29. ~SCRIPTS~
  30. ~
  31. ~This whole area, in the script editor, is the SCRIPT CONTAINER. It "contains" everything in the SCRIPT.
  32. ~
  33. ~"SCRIPT" is another word for "program". This SCRIPT will make text float above an object. On the screen you will see that the first two lines of this SCRIPT are "commented".
  34.  
  35.  
  36. ~
  37. ~// (Double forward slashes), before a line, make the line a comment. Comments are ignored by the script. Use comments for whatever you like.
  38. ~NextPicture
  39.  
  40.  
  41.  
  42.  
  43. ~
  44. ~Look at the first uncommented line in the program.
  45. ~
  46. ~STATES~
  47. ~default
  48. ~
  49. ~This is a STATE. It is named "default". "STATE" is another word for "sub-program". STATES are the "big shots" in a script. Almost everything in a script is contained inside of STATES.
  50.  
  51.  
  52. ~
  53. SCRIPTS may contain many STATES, but EVERY LSL SCRIPT MUST contain a STATE named "default".
  54.  
  55. ~
  56. ~STATES can be any name you wish. However, every SCRIPT must contain a STATE named "default", even if it does nothing, and each STATE must have a different name.
  57. ~
  58. ~"default" is the only STATE in this SCRIPT.
  59.  
  60.  
  61. ~
  62. ~Next line:
  63. ~{ OPEN CURLY BRACKET. This opens the STATE "container", which "contains" everything in this STATE. This container will remain open until closed with a closing CURLY BRACKET later.
  64. ~
  65. NextPicture
  66.  
  67.  
  68. ~
  69. ~EVENTS~
  70. ~ state_entry()
  71. ~
  72. ~This is an EVENT named "state_entry". This type of event will run as soon as the STATE starts or "upon entry of a STATE".
  73. ~
  74. ~Note that the underscore MUST be used. "state entry" does not equal "state_entry".
  75.  
  76. ~
  77. ~EVENTS are also called "Event handlers" because they "handle events." EVENTS are like inputs.
  78. ~
  79. ~The SCRIPT is looking for inputs such as - when a script runs, when an object is touched, when an object is collided with, etc.
  80.  
  81. ~
  82. ~Linden Scripting Language (LSL) is an EVENT BASED scripting language.
  83. ~
  84. ~There are approximately 40 EVENTS defined by Linden Labs, that you can use in your SCRIPTS, a few of which we will discuss in this class.
  85.  
  86.  
  87. ~
  88. ~THERE CAN ONLY BE ONE EVENT OF THE SAME TYPE IN EACH STATE.
  89.  
  90. ~
  91. ~Let's go to the next line.
  92. ~
  93. ~ { OPEN CURLY BRACKET. This opens the EVENT container. INSIDE of the open STATE container.
  94. ~
  95. ~We can say that this EVENT container is "nested" inside of the STATE container. This EVENT will stay open until closed by CURLY BRACKETS below.
  96. ~
  97. NextPicture
  98.  
  99.  
  100.  
  101. ~
  102. ~Next line.
  103. ~ llSetText("Put your text here.", <0.0, 0.0, 0.0>, 1);
  104. ~
  105. ~FUNCTIONS~
  106. ~
  107. ~ This is a FUNCTION named llSetText. It makes text "magically" appear above an object.
  108. ~
  109. ~Where EVENTS are the "listeners" in scripting, FUNCTIONS are the "doers" of the LSL scripting world.
  110.  
  111. ~
  112. FUNCTIONS are contained, in curly brackets, inside of the EVENT container.
  113. ~
  114. ~FUNCTION names begin with two lower case Ls ( "ll" ). FUNCTIONS require VARIABLES AND VALUES in parentheses. FUNCTION lines end with a semicolon ;
  115.  
  116.  
  117.  
  118. ~
  119. ~It is important to remember that SCRIPTS are case sensitive. "STATE" does not = "state". "Event" does not = "event". "llsettext" does != "llSetText".. ("!=" means "not equal")
  120. ~Figure 6
  121.  
  122.  
  123.  
  124. ~
  125. ~Note how the lines of the SCRIPT are INDENTED, TABBED, and SPACED, to show this STRUCTURE of FUNCTIONS, inside EVENTS, inside STATES.
  126.  
  127.  
  128.  
  129.  
  130. ~
  131. ~This is considered the proper way to write a SCRIPT, and makes the SCRIPT easy to read, understand, and edit.
  132. ~
  133. ~One of the biggest complaints, from established SCRIPT writers, is that people ask for their help on a SCRIPT that is a structural mess, and is, therefore, difficult to read.
  134.  
  135. ~
  136. ~Don't be one of "those" people.
  137. ~
  138. ~Respect the people who give you help by helping them read your script more easily.
  139.  
  140.  
  141.  
  142. ~
  143. ~Note that this SetText FUNCTION needs, inside of parentheses, (a STRING of text, a VECTOR of FLOATS for RGB color, and a FLOAT for opacity from 0.0 to 1.0). ~
  144.  
  145.  
  146. ~
  147. ~STRINGS, VECTORS, and FLOATS are TYPES of VARIABLES AND VALUES. Whereas VALUES are specific things lika a word or number, VARIABLES can represent many VALUES.
  148.  
  149.  
  150.  
  151. ~
  152. ~Let's look at what these TYPES of VARIABLES AND VALUES mean and do in the llSetText FUNCTION.
  153.  
  154. ~
  155. ~STRINGS~
  156. ~
  157. ~STRINGS are text VALUES or VARIABLES and are read exactly as written. This llSetText FUNCTION STRING says "Put your text here."
  158.  
  159. ~
  160. ~INTEGERS~
  161. ~
  162. ~INTEGERS are numbers with no decimals, like 1, 0, and -150000. You may not use commas in INTEGER number VALUES.
  163.  
  164.  
  165. ~
  166. ~FLOATS~
  167. ~
  168. ~FLOATS are decimal numbers such as 1.0, -0.1, and 3.14159265359
  169.  
  170. ~
  171. ~If a FUNCTION requires an INTEGER, and you use a FLOAT, you may get an error, or the program may round down your FLOAT to the next lower INTEGER.
  172.  
  173. ~
  174. ~If you use an INTEGER, like 1, in place of a FLOAT, the SCRIPT may let you get away with it and assume you meant 1.0...
  175.  
  176. ~
  177. ~It is best, IMO, to use INTEGERS and FLOATS properly to avoid "issues" and create a habit of being mindful of the difference between the two types of numbers.
  178.  
  179.  
  180. ~
  181. ~VECTORS~
  182. ~
  183. ~VECTORS are three FLOATS placed in angle brackets. "<>".
  184. ~
  185. ~Sometimes VECTORS are used for coordinates like <x, y, z>, but, in this case, the llSetText FUNCTION requires a VECTOR for RGB color. <R, G, B>
  186. ~
  187. ~RGB stands for Red-Green-Blue
  188.  
  189.  
  190. ~
  191. ~Millions of colors can be made by mixing various VALUES of Red, Green, and Blue.
  192. ~
  193. ~The VALUES for RGB colors, used here, are FLOATS. They are VALUES from 0.0 to 1.0.
  194. ~
  195. ~0.0 is no color.
  196. ~1.0 is full color.
  197. ~To make white, use full Red, full Green, and full Blue.
  198. ~To make black, use 0.0. for all three colors.
  199. ~To make Red, use 1.0, Red, 0.0 Green, and 0.0 Blue.
  200. ~To make purple, mix 1.0 Red, 0.0 Green, and 1.0 Blue.
  201.  
  202. ~
  203. ~STRINGS, FLOATS, and VECTORS. Those are all of the VARIABLES TYPES in this script. Let's look at the last VALUE we need to complete the llSetText FUNCTION.
  204.  
  205. ~
  206. ~OPACITY~
  207. ~
  208. ~OPACITY is the amount of visual "solidity" of something, or we might say OPACITY is the amount of light an object can block.
  209.  
  210. ~
  211. ~An OPACITY of 0.0 would be transparent, while an OPACITY of 1.0 is not at all transparent. At 1.0 an object is completely "opaque".
  212.  
  213. ~
  214. ~That's it for this llSetText FUNCTION. We have all of the VARIABLES AND VALUES we need. Let's "wrap it up".
  215.  
  216. ~
  217. ~Next line.
  218. ~ } CLOSE CURLY BRACKET closes this EVENT container, NESTED inside the STATE container. We are FINISHED with this state_entry() EVENT.
  219. ~
  220.  
  221. ~Next line.
  222. ~ } CLOSE CURLY BRACKET- Closes this STATE container. We are finished with this "default" STATE.
  223. ~
  224. ~We have "zipped up" the EVENT AND STATE containers. We now have a complete SCRIPT in a neat, well written, well structured package!
  225. ~5
  226. ~4
  227. ~3
  228. ~2
  229. ~1
  230. ~~~OKAY! FUN TIME!~~~
  231.  
  232. ~We have so far spent a good bit of time, a whole half an hour, just on reading and learning the basics.
  233. ~
  234. ~As we complete the lessons in this class, we will do more and more scripting and less and less reading, so prepare to have some fun, building your scripting muscles, because we're about to make stuff happen!
  235.  
  236.  
  237.  
  238. ~
  239. ~Exercise 1~
  240. ~
  241. ~Please place a box on the ground, preferably in a place where you can see one of the display screens at the same time.
  242.  
  243.  
  244. ~
  245. ~Select the "Content" tab in your build editing tool.
  246. ~
  247. ~Open your inventory.
  248. ~
  249. ~Open the "Lesson 1" folder in your inventory.
  250.  
  251.  
  252. ~
  253. ~Drag the script named "Script Set Text (Lesson Version)" into the content window.
  254.  
  255.  
  256. ~Open the script and close the build edit tool, but leave the script editor open.
  257.  
  258.  
  259. ~
  260. ~If you are having a hard time seeing everything at once...
  261. ~
  262. ~...try putting your script on one side of your screen, your chat on the other side, and your box where you can see it, and the display screen, at the same time.
  263.  
  264. ~
  265. Put your box up close to the display if you need to. It will not be in the way.
  266.  
  267.  
  268. ~
  269. ~You'll notice your box has some text floating above it now.
  270.  
  271.  
  272. ~
  273. ~Hover over the event and function names to see SYNTAX details. SYNTAX is the required structure of each part of the SCRIPT. See how the editor is helping you learn?
  274.  
  275.  
  276.  
  277. ~
  278. ~Note this state_entry event needs nothing inside the parentheses, but some events WILL need information there.
  279.  
  280. ~
  281. ~If you make an error in writing a SCRIPT, the script edit tool may tell you that you have a "SYNTAX ERROR". A SYNTAX error may mean you forgot something, like a parenthesis, or a semicolon, or you may have misspelled something.
  282.  
  283.  
  284. ~Hover over the SetText function to see syntax details. You will see that the function needs a string of text in quotes first.
  285.  
  286. ~
  287. ~Replace the text in the quotes with something you want the box to say.. Go ahead and do that now, then hit "Reset" to reset the script and see the results. If you get an error, let me know and we'll take a pause to help you fix it before we continue.
  288.  
  289.  
  290.  
  291.  
  292. ~
  293. ~Hover over the SetText function again. You will see that next it requires a vector of float numbers. Go ahead, now, and change the vector of three floats to make the text a different color, then reset the script to see the results of your work.
  294. ~ Here is a page of colors to help you out with mixing the color you want. http://wiki.secondlife.com/wiki/Category:LSL_Color
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301. ~
  302. ~Lastly, hover over the SetText function again and you will see the function requires a float for opacity. Go ahead, now, and change the float for opacity to 0.5 and reset the script to see your changes.
  303.  
  304.  
  305.  
  306.  
  307. ~That's it for this script. You know everything you need to know to put floating text over an object, in any color you want, and any opacity!
  308.  
  309.  
  310. ~~~NOTES~~~
  311. ~Note that the set text function is setting a prim parameter. That means that you can delete this script in the object, after the script has been run, and the text will remain.
  312.  
  313.  
  314. ~
  315. ~To change the text, after deleting this script, you will need to redefine it by using a script again, i.e., text "your text here".
  316.  
  317. ~
  318. ~If you plan on changing the text later, just un-check the "Running" check box in the script editor to stop the script from running needlessly.
  319.  
  320. ~
  321. ~This concludes lesson one. I have supplied a commented version of the script, with these notes in it, for you to review later.
  322. ~
  323. ~Any questions? Do you understand the structure of the script now? Do you understand what states are, what events are, and what functions are?
  324. ~
  325. ~Be sure you understand before we move on to the next lesson. It is better to ask now than to be confused later..
  326.  
  327. ~There is a notecard in your folder that will give you links to the LSL Portal and other sites that will help you learn more later.
  328. ~
  329. We've been working hard at learning scripts here! Let's take a short break and relax before the next lesson. Maybe you'll want to play with your new script. I find it very relaxing.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement