Friday, February 1, 2013

What is a script?

What is a script?

A script is list of commands that automate interaction to attain a specific goal. Scripts generally use JIT or AOT compilation methods. JIT is an acronym for “Just in Time” and AOT is “Ahead of Time” Blah, Blah, Blah. Whatever method of compiling or interpreting really means absolutely nothing to us. It is just nerd talk and not the reason we are here.

I’m NOT a Braniac I can’t script!

If you can type and carry on a conversation then you can script. Learning in small chunks is about the best way to grasp it. That is what we will be doing, small bits and dissection. Keep in mind we are not trying to run here just trying to stand up.
Here we will be doing things like telling the server to do stuff for us like “say something in chat” or “make that prim change colors”. You don’t have to worry about breaking SL with what we will be doing.

We will try to focus on a command or function one at a time.  I will also try hard to speak “engowish” to you too and not “techno nerd”.
To be an OK scripter you don’t need to know very many commands or functions. You just need to understand the format, “the structure” of how it is written and where to get information on commands and functions so that you can later understand what they do. Second Life has a nice WIKI that is dedicated to helping scripters.

The other beautiful thing about scripting is that breaking your script will push you to fix it. When you are pushed to fix it then you force yourself to learn. You accidentally learn how to script.
We are not here to write new scripts. Just edit what we have so it works better for our dance set. From this small step you may gain the ability to create new scripts.

 
It’s not like the Real World!

I have worked with seasoned RL professional coders in SL. Some have a hard time grasping LSL “Linden Script Language” and making it run efficiently. One of the reasons they sight is it is similar to core languages they use every day but yet bound by different rules.  They tend to make common mistakes based on their real life understanding of other languages. You have an advantage, you don't know the rules!

Done with the Pep Talk

The following are some links to information on scripting. If you find I am going to slow or want to just expand on what we are doing then these links are great place to start. We will also be referring back to some of these links for additional information in the course of this study.

The following link is a nice tutorial on starting your career in scripting. It covers the basics and will expand much of what we study here.


This link will take you to the LSL WIKI. This is one of the main locations scripters go to for information about anything LSL. You will find each command, function and event listed here. As you advance in your scripting abilities, this will become one of your main locations of reference.


 Take me to the code!

This is what I am going to assume you know.
You know the basics in SL such as,

Rezing a plywood box from the Building Tools editor.
Where the “contents” tab is in the Building Tools editor.

If you do not have this basic knowledge please familiarizes yourself with it before proceeding.


 
Start from the Start

1 Rez a new box on the ground, using the Build Tool editor.
 

2 Name the box “My First Script”.
 

3 Click the contents tab in the Build Tool editor.
 
4 Click the “New Script” button once.
 

If everything went right in public chat you should see “My First Script” say “Hello Avatar”.

5. In the contents tab list window you should see “New Script”. (This is not the button. This is an item listed in the window below it.) Click in the “New Script” that is in the window.
 

A window will pop-up and you should see the following stuff in the window.

 


OK so at this point you may be thinking you just beamed up to the “mother nerd ship”. *ROFL

The dissection

The first line of our code has the word “default” and then an opening bracket “{“.  Then we bounce to the very last line you see a closing bracket “}”. “default” is telling us this is where we start things. This is the default state of doing things. The “{“and “}” are telling us that the stuff in between them is owned by “default”.

Technical: “default” is a state. You could consider it a condition of being like the state of standing or the state of sitting. LSL "Linden Script Language" design focuses on using states, but there is a dark side to them that I won’t get into here. In our study we won’t confuse you with multiple states. We will only be working in the state of “default”. 

The next line you see is “state_entry()” this kind of like the doorway into our “default” state and it is considered an event. To super simplify things we are going to think of it as FIRST START HERE.  The next line you see is “{“and after the “llSay(0, "Hello, Avatar!");”  then you see “}”. When the script is started for its very first time the stuff inside the state_entry’s  open “{ “ and “}” close brackets is ran or executed.  In this case the function llSay is ran.

For some nerd info on llSay follow this link http://wiki.secondlife.com/wiki/LlSay. The anti-nerd translation for llSay in this context is simply, SAY “Hello Avatar!” in public chat.

All functions in LSL start with ‘ll” like “llSay”. I really don’t know why. My guess is they are saying “Linden Labs” or “Linden Language” to help define what the function is. Notice the “ll” is lower case. In the case of “llSay” we also see that the “S” is capitalized. You can expect this in all functions. Where the name or task will start with a capital for each word.  A good illustration of that would be “llOwnerSay” You see her the “O” and the “S” are capitalized.

 Whatever the function is, I like to break it down mentally. For llSay(0,”Hello Avatar!”);  I would think of it this way “linden labs Say (Send on Channel, “My Chat Text”); < Happy Ending<”.  Much of the time I am saying it out loud as I type.  This helps my mind convert it from some cryptic mumbo jumbo to thought that has meaning. Use whatever method helps you mentally navigate through the process.

Farther down you see “touch_start(integer total_number)”. This is an event. It has the customary “{}” brackets that define the block. The functions inside that block will be ran when the prim is touched by an avatar. In this case it uses the llSay function again and says "Touched.".

Technical: Events are chunks of code that are triggered when something happens like someone touching or colliding with an object. When the triggering activity takes place the block of code that defines the event is executed.


One thing to notice is that functions like llSay have a “;” at the end. This is like a terminator for the compiler. It is like saying Hey Mr. Computer this is the end of that line or end of that instruction.  I like to call it Happy Ending. *LOL

Notice that States and Events don’t have the “;” they have the “{ }”. Other types of flow control that we will get into later, will also use the “{ }” in it to define a block of code.
So at this point you are either bored, confused or the light went on. Either way we have taken our first steps at trying to understand a script. 


In our next study we will explore strobe effects and how to incorporate them into your dance stage.
Your home work is to explore what we just discussed, review the reference material and expand on the "Hello Avatar!" script. Try to add the llOwnerSay function to the script in place of the llSay function.



Disclaimer: If I have injured, caused distress, demoralized, altered your social status or flat out pissed off any nerds, please accept my sincerest “What Ever!” *LOL

See you on the dance floor!
Rachael “Nerd” Young