SlideShare a Scribd company logo
1 of 39
Pauli Pinelli Beginning Scripting in Second Life
Getting started in scripting in Second Life LSL stands for "Linden Scripting Language"  LSL is used to script the objects you will make in Second Life.  This tutorial is intended for those who have never programmed before in Second Life or elsewhere.  Scripting is harder to learn than basic object manipulation, but is very rewarding once you make progress. You will begin by running the standard “Hello Avatar " script and eventually move towards making your own.
What is LSL? Linden Scripting Language’s structure is based on Java and C.  Scripts in Second Life can be placed inside any object in the world, or any object worn by an avatar, but not inside an avatar.  They are written with a built-in editor/compiler.  LSL  has heavy emphasis on "States" and "Events". Many real life objects have "states" A door can be "open" or "closed" and a light can be "on" or "off".  A person can be "hyper", "calm", or "bored".  a script will have at least one state, the default state.  “event execution model”(unique in this way) An event can be thought to be a "Trigger". Events are predefined in LSL. Touch_start(), will trigger the code when the object is touched.
Linden Scripting Language “LSL” makes objects interactive Allows commerce, serious gaming, interfaces, web connectivity Linked objects may perform independent actions
WHAT CAN I DO WITH SCRIPTS?  Scripts can make an object: Move Listen Talk Operate as a car or gun Change color, size or shape  Talk to you Talk to another.
WHAT CAN I DO WITH SCRIPTS?  "Prim" or primitive, the basic building block can have a script. When several prims are linked, they can each contain a script which speaks to the rest of the object via Link Messages.  Here we focus on single scripts in a single prim.  If you've built in Second Life, everything you can define in the edit window can be defined in a script.  All interaction you see between objects or between avatars and objects is via scripts.  Learning more about the world and building model is vital to some aspects of scripting
Running Your First Script Traditionally one starts by writing the smallest program to print "hello world“. Since LSL only runs inside objects, you must know how to make an object and put a script inside it. You must be on land which allows building. In the edit window you may five tabs marked general, object, featurestexture and content,.  Click "content".
Running Your First Script Press "new script" to add a new script.  This will open the LSL editor with a default script.  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.  Hit "save" and close your edit window (not the LSL program window) You should see the words "Hello Avatar" from "object“  If you touch the object, it will say "Touched.“  (make sure the "edit" window is closed for touching to work. “ GOOD! You have compiled and run your first LSL script!
Write, run, RE-write Most scripts you make won't run the first time you run them.  When you hit "save" on a script, the LSL editor "compiles" the code to form SL can understand. It stops if it finds an error.  Brackets, parenthesis, and semicolons must all be perfectly in place  If you are new to programming this can be  frustrating 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.  Thus you will find yourself writing, running, then RE-writing your code several times.  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 Each time you re-write your code you must save the script.
A Closer Look The script: When I am in the default state, and I am touched, say “Touched" on channel zero".  The script: By start say “Hello, Avatar" on channel zero".
STATES  A "State" in LSL is a section that is running, and waiting for events. Only one state can be active.  Every script must have a default state with at least one event in it. Except for the default state, each state is defined by the word STATE followed by the name of the state.  The contents of the state are enclosed in two curly brackets.
EVENTS  Events are inside of states. When a state is active, those events wait to be triggered and run the code inside them.  "state entry" which is trigged by the a state being entered "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
FUNCTIONS  Functions lay inside of events and are either defined by you or built-in.  Those built in to LSL all start with two lower case L's. ex. llSay()  Functions take "arguments" or values in the parentheses that follow it If you hover over the function in the editor, a popup will show that tell you what the function is expecting. In the case of llSay it expects a number and a string.  llSay(0, "Touched.");
Putting it all together
After saving your script occurs following: 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.  After this the program waits idle in the default state until a new event is called.  Touching the box triggers the even "touch_start" which also makes the object speak.
Introducing States and Events LSL scripts will not run from 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. Lets look at a script with two states with two events in each.
A simplification of this would be default  {//set color to light and, if touched, enter the "off" state. } state off {//set color to dark and, if touched, enter the "default" state. } Note that after "default" all new states begin with the word "state".
A closer look llOwnerSay( "turning on!");  Object speaks to primitive owner!  A semicolon ends the line.  llSetColor(<1,1,1>, 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.
Color by Numbers
Program creates a loop 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.
Objects speaking is a great way to know what a script is doing  As you get into more complex scripts this can get pretty noisy to the surrounding people!  llWhisper( ) is just like llSay( ) but only broadcasts at half the distance. llWhisper(0,"turnign on!"); //might work a bit to save the sanity of your neighbors.  Using llShout( ) doubles the distance heard, but can cut the amount of friends you have in SL.  llOwnerSay( ) uses no channel and is heard only by you.
Totally silent message via llSetText( ) 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).
http://wiki.secondlife.com/wiki/Category:LSL_Functions
Rotate: llTargetOmega default { state_entry() 	{ llTargetOmega( < 0, 0, 1 >, .01, 1.0 ); 	} }
URL Loading: llLoadURL default
 {touch_start(integer total_number) 	{ llLoadURL(llDetectedKey(0), "Name", “site.com"); 	} }
Notecard Giver: llGiveInventory default { touch_start(integer total_number)     { llGiveInventory(llDetectedKey(0), “Write notecard’sname here");     } }
Floating text default { state_entry() 	{ llSetText(“Pauli Pinelli", <1,1,1>, 2.0); 	} }
http://wiki.secondlife.com/wiki/Category:LSL_Events
Interesting Events collision(integer total_number) sensor(integer total_number) money(key giver, integer amount) changed(integer changed)
Look at The door script ,[object Object],”SL scripting Basics Blue Door” ,[object Object]
Right click the mouse  and select edit
 Select content tab
 Double click the program named: “Door” ,[object Object]
Select take.
The object goes to the inventory (= briefcase box on the right side menu).,[object Object]
Variables what are then? Variables hold data They come in flavors (types) Have meaning to the ENTIRE script or only a portion of it Using them properly is one of the most important thing in scripting
Variable Types Float = floating point or real number Integer = positive whole number String = a text word or phrase Vector = a set of three floats rgb color, xyz pos, xyz vel, xyz accel Key = uuid - object identity Rotation = x,y,z,s - hard! List = rough database Typecasting a=(string)b

More Related Content

Viewers also liked

IJKK Second Life
IJKK Second LifeIJKK Second Life
IJKK Second LifePyy
 
SL rakentaminen ja ohjelmointi Pauli Pinelli
SL rakentaminen ja ohjelmointi Pauli PinelliSL rakentaminen ja ohjelmointi Pauli Pinelli
SL rakentaminen ja ohjelmointi Pauli PinelliPyy
 
SL in educating
SL in educatingSL in educating
SL in educatingPyy
 
Second life building
Second life buildingSecond life building
Second life buildingPyy
 
Sosiaalisen Median Käyttö Opetuksessa
Sosiaalisen Median Käyttö OpetuksessaSosiaalisen Median Käyttö Opetuksessa
Sosiaalisen Median Käyttö OpetuksessaPyy
 
The Content Inc. Model by Joe Pulizzi - Content Marketing Master Class 2016
The Content Inc. Model by Joe Pulizzi - Content Marketing Master Class 2016The Content Inc. Model by Joe Pulizzi - Content Marketing Master Class 2016
The Content Inc. Model by Joe Pulizzi - Content Marketing Master Class 2016Joe Pulizzi
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldabaux singapore
 

Viewers also liked (8)

IJKK Second Life
IJKK Second LifeIJKK Second Life
IJKK Second Life
 
SL rakentaminen ja ohjelmointi Pauli Pinelli
SL rakentaminen ja ohjelmointi Pauli PinelliSL rakentaminen ja ohjelmointi Pauli Pinelli
SL rakentaminen ja ohjelmointi Pauli Pinelli
 
SL in educating
SL in educatingSL in educating
SL in educating
 
Second life building
Second life buildingSecond life building
Second life building
 
Sosiaalisen Median Käyttö Opetuksessa
Sosiaalisen Median Käyttö OpetuksessaSosiaalisen Median Käyttö Opetuksessa
Sosiaalisen Median Käyttö Opetuksessa
 
The Content Inc. Model by Joe Pulizzi - Content Marketing Master Class 2016
The Content Inc. Model by Joe Pulizzi - Content Marketing Master Class 2016The Content Inc. Model by Joe Pulizzi - Content Marketing Master Class 2016
The Content Inc. Model by Joe Pulizzi - Content Marketing Master Class 2016
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Similar to Sl scripting in English

C++ Course - Lesson 1
C++ Course - Lesson 1C++ Course - Lesson 1
C++ Course - Lesson 1Mohamed Ahmed
 
Debugging NET Applications With WinDBG
Debugging  NET Applications With WinDBGDebugging  NET Applications With WinDBG
Debugging NET Applications With WinDBGCory Foy
 
Synthesis Examples
Synthesis ExamplesSynthesis Examples
Synthesis ExamplesMohamed Samy
 
Behavior Driven Development with Rails
Behavior Driven Development with RailsBehavior Driven Development with Rails
Behavior Driven Development with RailsMark Menard
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As CompDavid Halliday
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As CompDavid Halliday
 
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009Michael Neale
 
perl 6 hands-on tutorial
perl 6 hands-on tutorialperl 6 hands-on tutorial
perl 6 hands-on tutorialmustafa sarac
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping newaprilyyy
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!olracoatalub
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basicSara Samol
 
1.2 statements, properties, and operations
1.2   statements, properties, and operations1.2   statements, properties, and operations
1.2 statements, properties, and operationsallenbailey
 
Locking-Down Your Domino Web Environment
Locking-Down Your Domino Web EnvironmentLocking-Down Your Domino Web Environment
Locking-Down Your Domino Web Environmentdominion
 

Similar to Sl scripting in English (20)

C++ Course - Lesson 1
C++ Course - Lesson 1C++ Course - Lesson 1
C++ Course - Lesson 1
 
Debugging NET Applications With WinDBG
Debugging  NET Applications With WinDBGDebugging  NET Applications With WinDBG
Debugging NET Applications With WinDBG
 
Synthesis Examples
Synthesis ExamplesSynthesis Examples
Synthesis Examples
 
Behavior Driven Development with Rails
Behavior Driven Development with RailsBehavior Driven Development with Rails
Behavior Driven Development with Rails
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
 
Intro To Scratch
Intro To ScratchIntro To Scratch
Intro To Scratch
 
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
 
Scripting 101
Scripting 101Scripting 101
Scripting 101
 
Scripting The Dom
Scripting The DomScripting The Dom
Scripting The Dom
 
perl 6 hands-on tutorial
perl 6 hands-on tutorialperl 6 hands-on tutorial
perl 6 hands-on tutorial
 
Jquery 1
Jquery 1Jquery 1
Jquery 1
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
 
Introducing Small Basic.pdf
Introducing Small Basic.pdfIntroducing Small Basic.pdf
Introducing Small Basic.pdf
 
My final requirement
My final requirementMy final requirement
My final requirement
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basic
 
1.2 statements, properties, and operations
1.2   statements, properties, and operations1.2   statements, properties, and operations
1.2 statements, properties, and operations
 
Locking-Down Your Domino Web Environment
Locking-Down Your Domino Web EnvironmentLocking-Down Your Domino Web Environment
Locking-Down Your Domino Web Environment
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 

Sl scripting in English

  • 1. Pauli Pinelli Beginning Scripting in Second Life
  • 2. Getting started in scripting in Second Life LSL stands for "Linden Scripting Language" LSL is used to script the objects you will make in Second Life. This tutorial is intended for those who have never programmed before in Second Life or elsewhere. Scripting is harder to learn than basic object manipulation, but is very rewarding once you make progress. You will begin by running the standard “Hello Avatar " script and eventually move towards making your own.
  • 3. What is LSL? Linden Scripting Language’s structure is based on Java and C. Scripts in Second Life can be placed inside any object in the world, or any object worn by an avatar, but not inside an avatar. They are written with a built-in editor/compiler. LSL has heavy emphasis on "States" and "Events". Many real life objects have "states" A door can be "open" or "closed" and a light can be "on" or "off". A person can be "hyper", "calm", or "bored". a script will have at least one state, the default state. “event execution model”(unique in this way) An event can be thought to be a "Trigger". Events are predefined in LSL. Touch_start(), will trigger the code when the object is touched.
  • 4. Linden Scripting Language “LSL” makes objects interactive Allows commerce, serious gaming, interfaces, web connectivity Linked objects may perform independent actions
  • 5. WHAT CAN I DO WITH SCRIPTS? Scripts can make an object: Move Listen Talk Operate as a car or gun Change color, size or shape Talk to you Talk to another.
  • 6. WHAT CAN I DO WITH SCRIPTS? "Prim" or primitive, the basic building block can have a script. When several prims are linked, they can each contain a script which speaks to the rest of the object via Link Messages. Here we focus on single scripts in a single prim. If you've built in Second Life, everything you can define in the edit window can be defined in a script. All interaction you see between objects or between avatars and objects is via scripts. Learning more about the world and building model is vital to some aspects of scripting
  • 7. Running Your First Script Traditionally one starts by writing the smallest program to print "hello world“. Since LSL only runs inside objects, you must know how to make an object and put a script inside it. You must be on land which allows building. In the edit window you may five tabs marked general, object, featurestexture and content,. Click "content".
  • 8. Running Your First Script Press "new script" to add a new script. This will open the LSL editor with a default script. 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. Hit "save" and close your edit window (not the LSL program window) You should see the words "Hello Avatar" from "object“ If you touch the object, it will say "Touched.“ (make sure the "edit" window is closed for touching to work. “ GOOD! You have compiled and run your first LSL script!
  • 9. Write, run, RE-write Most scripts you make won't run the first time you run them. When you hit "save" on a script, the LSL editor "compiles" the code to form SL can understand. It stops if it finds an error. Brackets, parenthesis, and semicolons must all be perfectly in place If you are new to programming this can be frustrating 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. Thus you will find yourself writing, running, then RE-writing your code several times. 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 Each time you re-write your code you must save the script.
  • 10. A Closer Look The script: When I am in the default state, and I am touched, say “Touched" on channel zero". The script: By start say “Hello, Avatar" on channel zero".
  • 11. STATES A "State" in LSL is a section that is running, and waiting for events. Only one state can be active. Every script must have a default state with at least one event in it. Except for the default state, each state is defined by the word STATE followed by the name of the state. The contents of the state are enclosed in two curly brackets.
  • 12. EVENTS Events are inside of states. When a state is active, those events wait to be triggered and run the code inside them. "state entry" which is trigged by the a state being entered "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
  • 13. FUNCTIONS Functions lay inside of events and are either defined by you or built-in. Those built in to LSL all start with two lower case L's. ex. llSay() Functions take "arguments" or values in the parentheses that follow it If you hover over the function in the editor, a popup will show that tell you what the function is expecting. In the case of llSay it expects a number and a string. llSay(0, "Touched.");
  • 14. Putting it all together
  • 15. After saving your script occurs following: 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. After this the program waits idle in the default state until a new event is called. Touching the box triggers the even "touch_start" which also makes the object speak.
  • 16. Introducing States and Events LSL scripts will not run from 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. Lets look at a script with two states with two events in each.
  • 17.
  • 18. A simplification of this would be default {//set color to light and, if touched, enter the "off" state. } state off {//set color to dark and, if touched, enter the "default" state. } Note that after "default" all new states begin with the word "state".
  • 19. A closer look llOwnerSay( "turning on!"); Object speaks to primitive owner! A semicolon ends the line. llSetColor(<1,1,1>, 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.
  • 21. Program creates a loop 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.
  • 22. Objects speaking is a great way to know what a script is doing As you get into more complex scripts this can get pretty noisy to the surrounding people! llWhisper( ) is just like llSay( ) but only broadcasts at half the distance. llWhisper(0,"turnign on!"); //might work a bit to save the sanity of your neighbors. Using llShout( ) doubles the distance heard, but can cut the amount of friends you have in SL. llOwnerSay( ) uses no channel and is heard only by you.
  • 23. Totally silent message via llSetText( ) 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).
  • 25.
  • 26. Rotate: llTargetOmega default { state_entry() { llTargetOmega( < 0, 0, 1 >, .01, 1.0 ); } }
  • 27. URL Loading: llLoadURL default {touch_start(integer total_number) { llLoadURL(llDetectedKey(0), "Name", “site.com"); } }
  • 28. Notecard Giver: llGiveInventory default { touch_start(integer total_number) { llGiveInventory(llDetectedKey(0), “Write notecard’sname here"); } }
  • 29. Floating text default { state_entry() { llSetText(“Pauli Pinelli", <1,1,1>, 2.0); } }
  • 31. Interesting Events collision(integer total_number) sensor(integer total_number) money(key giver, integer amount) changed(integer changed)
  • 32.
  • 33. Right click the mouse and select edit
  • 35.
  • 37.
  • 38. Variables what are then? Variables hold data They come in flavors (types) Have meaning to the ENTIRE script or only a portion of it Using them properly is one of the most important thing in scripting
  • 39. Variable Types Float = floating point or real number Integer = positive whole number String = a text word or phrase Vector = a set of three floats rgb color, xyz pos, xyz vel, xyz accel Key = uuid - object identity Rotation = x,y,z,s - hard! List = rough database Typecasting a=(string)b
  • 40. Global vs Local Variables Declare global variables at top of the script - they are usable throughout Declare local variables inside the block it will be used in
  • 41. Loops for (j = 0; j < count; j++) { // do stuff here } do { // do stuff here and increment j } while (j < count); while (j < count) { // do stuff here and increment j }
  • 43. More info http://lslwiki.net/lslwiki/wakka.php?wakka=HomePage LSL 101: The Complete Newbie's Guide to Scripting in Second Life http://wiki.secondlife.com/wiki/SL_Cert_-_Basic_Scripting Read about programming in SL wiki.