Sorin Todys - Advanced expert with 20+ years of experience in virtual worlds
All classes take place in Alife Virtual World at our dedicated Alife Virtual School region
Learn and Grow at Alife Virtual World School
Part of The School of Creation | Difficulty: Intermediate
Welcome, creators! If you've ever looked at a static object in Alife Virtual and wished it could *do* something, then you've come to the right place. This course is your gateway into the fascinating world of the Linden Scripting Language (LSL). Scripting is the "brain" that gives objects behavior, turning a simple block of wood into a door that opens, a button that gives gifts, or a light that illuminates a room.
In SCR-301, we will demystify scripting and empower you to bring your own creations to life. We'll start from the very beginning, understanding the core concepts of LSL, and by the end, you'll have scripted your very first interactive object that responds to you and other avatars. This is a hands-on, practical course designed to give you a solid and confident start.
Upon successful completion of this course, you will be able to:
llSay() function.touch_start event to make objects respond to clicks.llSetColor() function and vector data types.By the end of this course, you will have moved beyond being a static builder and will have become an interactive creator. You will master the ability to take any basic prim you create and imbue it with life. You'll be able to confidently build objects that greet visitors, change appearance on command, and function as simple devices. This foundational knowledge is the most crucial step in your journey to becoming an advanced LSL scripter.
This course is taught by Sorin Todys, our resident expert in the Linden Scripting Language. With over 20 years of experience scripting in virtual worlds, Sorin has a unique talent for making complex programming concepts easy to understand for beginners and intermediate learners alike. He is passionate about empowering students to unlock their full creative potential through code.
Think of a script as a recipe or a set of instructions that you place inside an object. The object will follow these instructions precisely. LSL is an event-driven language. This means a script spends most of its time waiting for something to happen (an "event"). Events can be anything: an avatar touching the object, a timer going off, or a message being received from another script.
When an event occurs, the script looks for a matching set of instructions (an "event handler") and executes the code inside it. The fundamental structure you'll always see is:
default. States help organize your script's behavior, like having a "door open" state and a "door closed" state.touch_start, which fires when someone clicks on the object.llSay()), change color (llSetColor()), or move (llSetPos()). Every function call must end with a semicolon ;.Let's make an object say "Hello, World!" when you touch it. This is the traditional first step in learning any new programming language.
Create. A build menu will appear. Click on the ground again to "rez" (create) a simple wooden cube. This cube is our object, or "prim."Edit from the pie menu. You'll see arrows and tools appear around your object.Content tab. This is the inventory of the object.New Script button. A new item named "New Script" will appear in the Content tab, and the script editor window will open, pre-filled with a default script.default { ... }: This is our main state. All the code lives inside these curly braces.state_entry() { ... }: This event runs once when the script first starts or is reset. Here, it makes the object say "Hello, Avatar!".touch_start(...) { ... }: This event runs every time someone touches the object. Here, it makes the object say "Touched.".Save button at the bottom of the script editor. The script will compile. If there are no errors, the button will become grayed out. If there are errors, they will appear in the chat window below the code. The most common error is a missing semicolon ;![Object] YourObjectName: Hello, World! You touched me.default state: The primary container for your script's logic.touch_start() event: The trigger that executes code when an object is clicked.llSay() function: The command to make an object speak in local chat.;: The most important piece of punctuation in LSL. Every complete command statement must end with one. Forgetting it is the #1 cause of syntax errors.Congratulations! You've just written your first working script and created an interactive object. You've taken your first step into a larger world of creation!
In Lesson 1, our object did the same thing every time. To make it more dynamic, we need to introduce variables and new functions. A variable is like a labeled box where you can store information for the script to use later. This information can be a number, a piece of text, or even a color.
integer: A whole number (e.g., 5, -10, 1000).float: A number with a decimal point (e.g., 3.14, -0.5).string: A piece of text, enclosed in double quotes (e.g., "Hello, Sorin!").vector: A set of three floats, used for positions, forces, and most importantly for us, colors (e.g., <1.0, 0.0, 0.0> for red).key: A unique identifier for any person, object, or item in the world.llSetColor(vector color, integer face): This function changes the color of the object. It requires a vector for the color and an integer specifying which face of the prim to color. We can use the special constant ALL_SIDES to color the entire object.llDetectedKey(integer index): When used inside a touch event, this function returns the unique key of the avatar who touched the object.llGetUsernameFromKey(key id): This function takes a user's key and returns their username as a string.Let's modify our script to make the block turn bright red when touched.
touch_start event. We'll add the llSetColor function.
Note on Colors: Color vectors use RGB (Red, Green, Blue) values from 0.0 (none of that color) to 1.0 (full intensity). So <1.0, 0.0, 0.0> is pure red, <0.0, 1.0, 0.0> is pure green, and <1.0, 1.0, 1.0> is white.
Note on Comments: The line starting with // is a comment. The script ignores it. It's for you to leave notes for yourself or others reading your code!
Save and close the editor. Touch your cube. It should now turn bright red and speak to you!Now, let's make the greeting personal. Instead of "Hello, World!", it will say hello to the specific person who touched it.
Right now, our object does one thing when touched. What if we want it to do one thing on the first touch, and something different on the second touch? This is where states become incredibly powerful. We can create a script that acts like a light switch: the first touch turns it on, the second turns it off.
To do this, we will create two states: an "off" state and an "on" state. We will use the default state as our "off" state, and we will create a new, custom state called on.
This is a classic and highly useful script. It demonstrates states, changing visual properties, and even adding light to the scene.
on, off, open, closed) makes your code much easier to read.state_entry: The state_entry event is perfect for setting up the initial appearance and properties of an object as soon as it enters a new state.