Posted on

Tutorial LSL 103 Class Note

Basic Scripting 103 (Beginners with no programming experience)
Welcome to my basic scripting class.
~============== Introduction ======================
This class is for beginners who don’t have any experience at all in programming.
If you already have scripting experience in any other language, please consider to take one of the intermediate classes instead. You are welcome to stay but it may be boring 😉
We’re hiring teachers here at the Academy of Second Learning, so if you’d like to help us bring great classes to Second Life, please pick up an application from the blue square sign outside.
Today I will tell you what a script is and how you can create and change it.
This will be very basic and I try to explain anything that is important to start your first script.
Anyway, you may find some stuff confusing if you hear it the first time, and you don’t need to understand all the technical details to create your first script.
So please bear with me, if some of it sounds Chinese to you. You will understand it later. If you have questions, please wait until I did all the explanations.
I will stop from time to time and give you a chance to ask questions.
~========= Chat Issues =============
Make sure to open your chat history (you can use CTRL-H to do this). You can catch up with chat lines that you may have missed.
Later on, after the class, you will be able to select all the chat lines with your mouse, or just click into it and press CTRL-A to select all.
You can then copy the chat history into the clipboard by pressing CTRL-C and pasting it later in any text editor of your choice or in a new note card by pressing CTRL-V.
~================ Presenter issues ==============
I hope you can see the presenter screen with the screenshots. If it is blurry, please wait a while until the images are loaded. It should become clear after a minute.
You can speed it up if you zoom in your camera to make it full screen. You can also right-click on it and choose “Edit”.
Even if you are not allowed to edit the object, it will put the image first into the loading-queue, which means, the presenter image will load next on your computer.
We will create our own script today from scratch. Anyway you will get class notes after class to review all the details.
For now it’s important that you just get a hands-on experience with your first script.
If you have to choose between understanding and a working script, choose the working script and re-read the class notes later, that’s much more fun 😉
Anyway feel free to stop me if I’m going too fast for you to read all the stuff 😉
~===================== Default Script basics =========================
We have learned in “basic scripting 102” how to create a default script.
To do that, please REZ a PRIM (any prim will do), I will do a BOX here.
It’s always a good idea to rename everything after creation.
So go to the GENERAL tab and name your object “My scripted Object”
Now, change to the CONTENT tab and click on NEW SCRIPT
There will be now a new script named NEW SCRIPT
You can rename it to a more meaningful name.
RIGHT-CLICK on the name and choose RENAME
Name it now “My first Script”
Now open the script by DOUBLE-CLICKing it
You can also RIGHT-CLICK and choose OPEN
You now see the default script with the default state and the events state_entry and touch_start.
Now prevent the spam from the script by adding the characters // at the beginning of the line:
// llSay(0, “Hello, Avatar!”);
The // will tell the script to ignore the whole line, you know that from the 102 class already.
When you have disabled the llSay-Line, and you save your script now (just click on the save button), we should no longer have these “Hello, Avatar” in the chat.
Anybody could manage that?
~=============== Functions ================
Now, let’s go on to change the Function call in touch_start:
To avoid text spam from the object here in class, change the line with llSay to another function. The new Function is llOwnerSay and you have to change the line like this:
Make sure you delete the first parameter (the number 0 and the comma) from the parameter list.
Then hit “save” and wait a moment. Saving the script may need a few seconds. It will say “Save complete” if there was no error in the script.
All okay so far?
llOwnerSay has the same effect as llSay, but the text will only show up in the chat window of the object’s owner.
So everybody can only hear their own object.
You can do other fancy things in the touch_start event. We will come back to that later.
~======================== add line llText to event_start =======
Now add the following line in the state_entry section. Just make sure you put the line between the curly brackets { and }
llSetText(“I am a scripted object”, <1, 1, 1>, 1);
If you click on save, and you don’t see an error message, there should be a text message hovering over your object.
Does it work for everybody?
Now let me explain what you just have done 😉
llSetText is a Function that needs three parameters.
The first is a string with the text that shall show over the object.
The second is a special thing with three numbers. This “thing” is included in < and > and it is called a VECTOR.
A vector is just a set of three numbers, normally used for position coordinates, but in this case it is used for a color.
The numbers are the intensity for the colors RED, GREEN and BLUE, where 1 means “full intensity” and 0 means “no intensity”
So <1, 1, 1> is WHITE, while <0, 0, 0> is BLACK
Other colors can be <1, 0, 0> for RED, or <0.5, 0.5, 0.5> for GREY.
Just try out several numbers. Just make sure the number needs a point as decimal point, and each number is separated by a comma.
The third parameter for llSetText is ALPHA which means the transparency of the text.
In this case, 1 means it has no transparency, 0 means it is transparent (invisible), and you can use any number between like 0.3 or 0.8 for example.
There is something special: If you remove the llSetText() in your script, the text will NOT go away 😉
This is because the text is an attribute of the object. If it is set, it will stick until you change it.
The only way to remove a hover text is to apply a blank text to the object.
To do this, change your line to:
llSetText(“”, <1, 1, 1>, 1);
Make sure you use the quotation mark ” twice to indicate an empty text.
If you now save the script, the text will disappear.
Does it work?
~========== Conclusion ==============
This concludes this class.
Now you will be able to create your own simple script.
You are able to use llSetText to add a hovering Text to your object and remove it later.
You are able to use llSay and llOwnerSay to let your Object speak with everybody or just with you.
Thanks for your time 😉


About Kemo

I am just an ordinary person in the garden.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s