SLscripting in English

4,716 views

Published on

Basics

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,716
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

SLscripting in English

  1. 1. Pauli Pinelli<br />scripting in Second Life<br />
  2. 2. Getting started in scripting in Second Life<br />LSL stands for "Linden Scripting Language" <br />LSL is used to script the objects you will make in Second Life.<br />This tutorial is intended for those who have never programmed before in Second Life or elsewhere. <br />Scripting is harder to learn than basic object manipulation, but is very rewarding once you make progress.<br />You will begin by running the standard “Hello Avatar " script and eventually move towards making your own. <br />
  3. 3. What is LSL?<br />Linden Scripting Language’s structure is based on Java and C. Scripts in Second Life are a set of instructions that can be placed inside any object in the world, or any object worn by an avatar, but not inside an avatar. <br />They are written with a built-in editor/compiler. <br />LSL has heavy emphasis on "States" and "Events". Many real life objects have "states"<br />A door can be "open" or "closed" and a light can be "on" or "off". <br />A person can be "hyper", "calm", or "bored". <br />a script will have at least one state, the default state. <br />An event can be thought of as a "Trigger". Events are predefined in LSL.<br />Touch_start(), will trigger the code in it when the object having the script is touched. <br />
  4. 4. WHAT CAN I DO WITH SCRIPTS? <br />Scripts can make an object:<br />Move<br />Listen<br />Talk<br />Operate as a car or gun<br />Change color, size or shape <br />Talk to you<br />Talk to another. <br />The script:<br />When I am in the default state, and I am touched, say "Hello World" on channel zero". <br />
  5. 5. WHAT CAN I DO WITH SCRIPTS? <br />"Prim" or primitive, the basic building block can have a script.<br />When several prims are linked, they can each contain a script which speaks to the rest of the object via Link Messages.<br /> Here we focus on single scripts in a single prim. <br />If you've built in Second Life, everything you can define in the edit window can be defined in a script. <br />All interaction you see between objects or between avatars and objects is via scripts. <br />Learning more about the world and building model is vital to some aspects of scripting<br />
  6. 6. Running Your First Script<br />Traditionally one starts by writing the smallest program to print "hello world“.<br />Since LSL only runs inside objects, you must know how to make an object and put a script inside it.<br />You must be on land which allows building.<br />In the edit window you may five tabs marked general, object, features, content, and texture. <br />Click "content". <br />
  7. 7. Running Your First Script<br />Press "new script" to add a new script. <br />This will open the LSL editor with a default script. <br />This editor will color code your syntax and provide some info about keywords when you hold your mouse over them. It will also do basic syntax checking. <br />Hit "save" and close your edit window (not the LSL editor window)<br />You should see the words "Hello Avatar" from "object“ <br />If you touch the object, it will say "Touched.“ <br />(make sure the "edit" building window is closed for touching to work. <br />GOOD! You have compiled and run your first LSL script!<br />
  8. 8. Write, run, RE-write<br />Most scripts you make won't run the first time you run them. <br />When you hit "save" on a script, the LSL editor "compiles" the code to form LSL can understand. It stops if it finds an error. <br />Brackets, parenthesis, and semicolons must all be perfectly in place <br />If you are new to programming this can be frustrating<br />Part of a programming in ANY language is learning how to precisely define steps and correctly type them into the language you are working in. <br />Thus you will find yourself writing, running, then RE-writing your code several times. <br />The script you made runs the instant you hit save. If you take it into inventory, it will "suspend" what it was doing but go right back to it when rezzedagain<br />Each time you re-write your code you must save the script. <br />
  9. 9. A CloserLook<br />
  10. 10. STATES <br />A "State" in LSL is a section that is running, and waiting for events.<br />Only one state can be active at any one time per script. <br />Every script must have a default state with at least one event in it.<br />Except for the default state, each state is define by the word STATE followed by the name of the state. <br />The contents of the state are enclosed in two curly brackets. <br />
  11. 11. EVENTS <br />Events are inside of states.<br />When a state is active, those events wait to be triggered and run the code inside them. <br />"state entry" which is trigged by the a state being entered<br />"touch start" which is triggered when you, or anyone, touches an object. Lets take a look at the default code. default // state{ touch_start(integer total_number) // this is an event { // this is the content of the event } // end of event } // end of state <br />
  12. 12. FUNCTIONS <br />Functions lay inside of events and are either defined by you or built-in. <br />Those built in to LSL all start with two lower case L's. ex. llSay() <br />Functions take "arguments" or values in the parentheses that follow it<br />If you hover over the function in the editor, a popup will show that tell you what the function is expecting.<br />In the case of llSay it expects a number and a string. <br />llSay(0, "Touched.");<br />
  13. 13. Putting it all together<br />
  14. 14. After saving your script occurs following:<br />The instant you save your script, it enters default state, which in turns runs the "state_entry" event which in turn runs the function llSay() which makes the object talk. <br />After this the program waits idle in the default state until a new event is called. <br />Touching the box triggers the even "touch_start" which also makes the object speak.<br />
  15. 15. Introducing States and Events<br />LSL scripts will not run beginning to end . Instead they will look for a default state and wait for an event. Within those events, there can be a call to go to a new state.<br />Lets look at a script with two states with two events in each.<br />
  16. 16.
  17. 17. A simplification of this would be<br />default <br />{//set color to light and, if touched, enter the "off" state.<br />}<br />state off<br />{//set color to dark and, if touched, enter the "default" state.<br />}<br />Note that after "default" all new states begin with the word "state". <br />
  18. 18. A closer look<br />llSay(0, "turning on!"); Channel zero is the channel you see all public chat on. A semicolon ends the line. <br />llSetColor(<0,0,0>, ALL_SIDES); This turns the prim to it's brightest tint. You see it as bright white . The three 0's stand for the black and the three 1's stand for the white. <br />
  19. 19. Program creates a loop<br />1. Enters default state 2. Runs code in "state entry" 3. Waits to be touched. 4. When touched enters "state off" 5. Enters "state off". 6. Runs code in "state entry" in the "off" state's body 7. Waits to be touched in the "off" state's body 8. When touched enters "default" state. Where the whole thing starts over.<br />
  20. 20. Objects speaking is a great way to know what a script is doing <br />As you get into more complex scripts this can get pretty noisy to the surrounding people! <br />llWhisper( ) is just like llSay( ) but only broadcasts at half the distance.<br />llWhisper(0,"turnign on!"); //might work a bit to save the sanity of your neighbors. <br />Using llShout( ) doubles the distance heard, but can cut the amount of friends you have in SL. <br />llOwnerSay( ) uses no channel and is heard only by you.llOwnerSay("turnign on!"); <br />
  21. 21. Totally silent message via llSetText( )<br />You can make a totally silent message via llSetText( ) like this. llSetText("I am on", <1,1,1>,1.0); <1,1,1>, means "white" and <0,0,0> means "black". Replace the llSay(0,"turnign off!"); with... The 1.0 is the alpha setting. 1.0 means fully opaque, and 0.0 would be completely transparent (invisible). <br />Read about programming in SL wiki.<br />http://wiki.secondlife.com/wiki/SL_Cert_-_Basic_Scripting<br />
  22. 22. http://wiki.secondlife.com/wiki/Category:LSL_Functions<br />
  23. 23. http://wiki.secondlife.com/wiki/Category:LSL_Events<br />
  24. 24.
  25. 25. Do the scripting!<br />

×