The programming language for Second Life
To begin: If you are on your own land, good! You can do what you want there. If you are somewhere else in SL, then either go back to your own land or go to a sandbox before starting this step, so that you can run your scripts. Check the top of your screen.
Make sure that, at the top of your screen next to Help, there is no "Scripts disabled" icon. If there is, you'll need to find somewhere else to do this step.
To create an object: Right click on the ground and select Create. This will make your cursor into a wand. Right click on the ground again, and you will create an object!
Click on the More>> button, and you will see that you can change the object's shape, size, and surface texture.
Try it!
- Create an object
- Make it into a sphere
- Make the surface "texture" be zebra skin.
- When you have it the way you like it, click on take -- that puts it into your Inventory!
- Make sure you can see your new object in your Inventory.
- Drag two copies of it back out, and then delete them, just for fun.
A script is a kind of "high level" program, one that controls what other programs do. In Second Life, scripts control the avatars and objects. Let's make an object and create a script to control it.
As you did before, create an object by right clicking on the ground and then selecting Create. With your wand, right click on the ground again tocreate an object! Click on the More>> button, then on the Content tab.
The real fun starts now. Click on the New Script... button. You should see a "Hello, Avatar!" message. Where is that from? You can find out by right clicking on the New Script that is in under your Content button, and you should see this:
default { state_entry() { llSay(0, "Hello, Avatar!"); } touch_start(integer total_number) { llSay(0, "Touched."); } } This is the Second Life script editor. The lines are numbered here but not in the Second Life editor. Instead, in the editor, the bottom of the window shows the line and column where your cursor is -- this is shown because in a script, every detail matters!
The braces {..} hold blocks of code. In the script just above, the block that goes from line 2 to line 12 is the default block, the block that tells the avatar what to do when it is in the default state.
In the default state, there are various different events that could happen. Whenever the object enters the default state, that event is called the state_entry, and what we do then is defined by the code block that goes from line 4 to line 6.
When the object is touched, that's called a touch_start event, and what the object does then is defined from line 9 to line 11.
llSay is a command. Each command ends with a semicolon, and sometimes the details about what to do are given by the "parameters" between parentheses. The 0 means that the object should say something out loud, in public. (We'll explain more about this later.) And then you put what the object should say between quotes. This quotation is called a string.Try changing what the object should say when it gets touched, press save, then try touching your object and see if it works!
(Some more details are covered on the worksheet 00, near the bottom of the link page here)