Topic Summary:

  1. Introduction
  2. Quick overview of scripts
  3. How to add scripts to a prim
  4. Animate textures
  5. Minor script tinkering
  6. Change Text Colour
  7. SetText Script
  8. Ready To Use Scripts
  9. Poseball scripts
  10. Scripting Links
  11. Project: Water Fountain

Class 10: Adding Scripts to Prims

Introduction

The Linden Scripting Language, LSL for short, provides the opportunity for objects in SL to be interactive and to interact with the world and people around them.

This tutorial is targeted at people with little or no experience in writing scripts and code. In this tutorial I will not attempt to teach you how to write scripts, (you'll only laugh at me!).

But I will show you how to use existing scripts, and where possible, make some very small adjustments to these existing scripts to customise them for your building needs. We can add scripts and various animations and special effects to a prim to create some very complex actions and effects.

In this very simple demo, I have flattened a Torus, added a water texture, then added an animation script to move the water texture along the surface of the Torus. Tadaaaa!! I now have a whirlpool of water just off the edge of the water, ready to suck you in.

demo water feature

Back to Top


Quick overview of scripts

Scripts can be a bit daunting for a non-coder, as well as a beginner builder. But, in this class, I am going to show you that:

  1. You don't need to know how to write code to use scripts in SL
  2. Give you the confidence to customise existing free scripts by making some minor changes

Good script writers add lots of comments inside their scripts that explain what their script is doing, and what variables can be changed. When you open up a script to see the code, the comments are in the orange coloured text and start with two slashes.

// Replace "ADD YOUR TEXT HERE" with your own text for the hover text
⁄ ******** Do Not Modify ANYTHING Below This Line ********** //

Unfortunately, not all scripts have comments, so it makes modifying them or re-using them just that little bit more complicated! While a little knowledge can be dangerous regarding script tinkering, I still feel its worth while having a bit of a play and see what results you get.

Tip: Make sure you tinker with a copy of a script, not the original script; that way, even if you totally stuff it up, just delete the evidence, make another copy and start again. :)

Of course, you can only modify scripts that have MOD permissions, and copy scripts that have Copy permissions.

If you need to learn more, I strongly urge you to use Search and find classes that are specifically targeting at Scripting topics as this.

PS - Scripting From Scratch offers great scripting classes aimed at total beginners; look out for these classes in Search or join the Friends of SL Group to obtain further information on class details

Back to Top


How to add scripts to a prim

All scripts, sound effects, particle effects, animations, configuration notecards are added to prims via the Contents Tab. Depending on the script you want to use, you may have to add the script to the Root Prim, while for other scripts, you can add the Scripts into the Contents tab of any prim. I can't offer you a cast iron rule on which prim to use for your script as this is totally dependent on the actual script itself and the actions it is programmed to perform.

Contents Tab

To add items into the Contents tab you also need to have your Inventory folder open. Locate the script, or any other item you want to add, then drag the script from your Inventory folder and drop it into the contents tab. Wait a few seconds for it to appear.

For example, if I have a Light Switch script that turns the light on and off, I could probably add that script to the base of the lamp object, or even the lamp shade. On the other hand, if my light switch script was written to also send out additional messages to other prims that also have scripts in them e.g.: to the Light Highlight script inside the Light Bulb prim to light up, then I would ensure that the light switch script was in the Root Prim.

OK, let's get some Scripting action happening!

Back to Top


TextureAnim Script (Texture Animation)

Texture animation scripts move the texture along the surface of the prim. The common movements are to rotate a texture, or to move it in a continuous loop. One example you may have seen in SL is moving water in water falls, or water fountains, where the water texture is animated to move along the surface of the prim.

Let's see this script in action.

Rez a Torus. Make the following changes to the Object tab:

In the Texture Tab, make the following changes:

Let's see what we have created so far.....

Torus with static texture

Now, drag and drop the script called TextureAnimslow into the Contents tab. Wait a few seconds for the Content tab to be updated with the script and for the script to start.

Now look at the Torus!

(Close your eyes and imagine the texture is moving along the surface of the prim.... OK?)

Torus with moving water texture

Let's take a quick peek at the actual code for this script.

Back to Top


Minor Script Tinkering

To open a script, locate the script in the Contents tab, then double-click on it to open it. The Script editing window will open and you will see the actual code.

Don't forget, if the script you are using is No Mod, you will not be able to view the code nor make any changes to it!

TextureAnimslow script

OK, on to dissecting this script.

Firstly, we can see that it is a simple script - with 1 line of code that we are really interesting in tinkering with.

llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, ALL_SIDES, 0,0,0.0, 1.0, 0.015);// 0.015 is speed of animation

Hoookay... remember that this is the non-coders class on scripts, so I am not going to even attempt to explain what all that means... BUT...

I CAN determine from the comment // 0.015 is speed of animation that the very last set of numbers: 0.015) is what I can change to alter the speed of the texture animation.

Now, for these next few steps, you are going to have to try them on your own as I cannot actually show the effects here on this page :)

Change the 0.015 number to 1.0, then click on the Save button at the bottom right hand corner of the script editing window.

In the bottom left hand corner you will receive messages on the status of the script save process: Compile successful, Saving... and eventually you should see the message: Saved

If you have made an error when making your changes, especially an error to the logic of the script, then you will receive an error message from the script compiler listing the row and column number position numbers of the error. You will have to make the required corrections to the script, then attempt to re-save it. SL will not let you save a script that has a logic or compile error; you will have to correct the error if you want to proceed.

As you tinker and adjust scripts, you will probably encounter this problem quite frequently. Its all part of the learning process :)

Besides, what's the worst that can happen? You delete the copy of the script and start again with a new copy.

You were working from a copy of a script, not the original script, right??!

Back to Top


SetText Script (Hover Text)

Let's look at the SetText script. This is a common script that you can see on various prims e.g.: Touch me for a Landmark, For Sale, Class Supplies

We are going to change the words of the hover text and the colour of the text by making some small adjustments to the SetText script.

SetText Script

See, this is a GREAT example of a well commented script that is very helpful to new scripters! It tells us exactly what this script is about, and how we can make changes to it.

The line of code that determines the text that is displayed above the prim, and the colour of that text is:

llSetText("TEXT GOES HERE", <1.0,1.0,1.0>, 1>;

Reading the comments that are included in this script, I know the following about the script:

OK, lets tinker with the first part of this script. Replace the TEXT GOES HERE with your own text. I am going to change the hovering text to say: Tickle me for Class Supplies.

Be careful not to accidentally delete the double quote marks; they must surround the text you want to display above your prim. If the quote marks are missing from the start or end of your string of text, the compiler will return a compile error. (And we don't want to happen, right??)

When you look at your prim, the words of the hover text have been changed, just as you told the script to do.

Change text to script

If you get an error message when trying to save, the row number and character position of the first error is included in the error message, giving you the opportunity to review the script changes you have made and make the required corrections. You cannot use a script that has not been saved successfully.

Compiler Error Message

Change Text Colour

Now, on to the colour of the hovering text. The colour values used in SL scripts are Colour Vector values, not the familiar RGB numbers. I am going to skip right over the how and why of these values and just say - use the Colour Table below to pick a value and add it to your script.

Click on the image to open a larger image

There are a lot more colour values that you can use for your scripts - I've seen colours specified down to 6 decimal points! But, for the purposes of choosing a text colour, I feel that there are more than enough colours to choose from.

Here's my quick list of basic colours:

I want to change the colour of my hovering text to RED. Looking at the Quick List of colours, I can see that Red: <1.0,0.0,0.0>, so I will update the Set Text with this set of values.

llSetText("Tickle me for Class Supplies", <1.0,0.0,0.0>, 1>;

The final portion of this line of code refers to the transparency setting of the hover text. As the comments in the code advise, a value of 1 means the text is fully solid, and a value of 0 makes my text totally transparent. Hmmm, I'm going to leave it at the current setting of 1.

Here is my updated script, and here are the changes as they appear on my Prim:

New hover text settings based on script changes

Back to Top


Ready-Made Scripts

There are some Ready-Made scripts, as I call them, where you can use them As-Is, with no tinkering required. Just drag and drop the script from your Inventory folder and drop it into the Contents tab of your prim.

Examples include:

Give Notecard
Drag a notecard into the Contents tab of your prim, then drag and drop the Give Inventory script too. When a person touches the prim, it will give them a copy of the Notecard
Give Inventory
This script is similar to the Give Notecard script, but it gives multiple objects to the person who touched the prim with the script. For example, give out a Notecard and a Landmark and a gift for potential customers to come and visit your store, or give out Class Supplies to students.

Contents Tab for Ready Made Scripts

Back to Top


Poseball scripts

Adding scripts to poseballs is another common building task that you can perform even if you are a beginner builder. There are two types of poseballs scripts that are freely available for builders to use:

The Nyterave script is another example of a well documented script that gives you, the beginner builder enough information to be able to tinker with the settings with confidence.

While it is a long script, you only need to adjust the 6 settings that are located as the very start of the script. In fact, the scripter's comments for this script clearly tell you:

//* * * * * * * * * MODIFY BELOW * * * * * * * * *//

and

//* * * * * * * * * STOP MODIFY * * * * * * * * *//

Here's a fragment of the beginning section of the script:

Nyterave Script Fragment

From the clear and extensive comments, the following fields can be changed:

To use the Nyterave script, drag and drop it into the Contents tab of your Pose ball prim, then also add the poseball sit script you want to use. Double click on the script to open it in the Script Editing window and make the changes you want to the settings and Save the script. The contents tab will flicker slightly as the script changes are saved into the prim. While the Edit window is still open, sit on the poseball, then adjust its position and rotation till you get your sit pose, just right.

Contents Tab with Nyterave Script and Sit animation

The other common Pose ball script that you may like to tinker with is the Pose ball 4.3 script. This script is slightly different from the Nyterave script, in that is uses a Pose ball CONFIGURATION notecard. You enter the variables, like Hover Text, Sit Text into the Notecard, and the script uses the values in this notecard to execute the script. The script also has default values that it can use in case it does not find a Configuration Notecard in the Contents tab.

PS: Using a separate configuration notecard that has Modify permissions allows the script writer to make the code of the Pose ball script No Modify.

To use this script, add the Pose ball - CONFIGURATION notecard, the Pose ball 4.5 script and the sit animation into the contents tab of your poseball prim. Double click on the CONFIGURATION notecard and make the changes to the settings, then Save the notecard. As before, the contents tab will flicker slightly as the script changes are saved into the prim. While the Edit window is still open, sit on the poseball, then adjust its position and rotation as you require.

Contents Tab with Poseball Script, Configuration Notecard and Sit animation

Back to Top


Scripting Links

Where to go from here?

As I stated at the start of this class, this is a non-coders introduction to minor script tinkering. If you want to learn more about scripting I would strongly recommend that you look for classes that are specialise in scripting for scripters.

Back to Top


Project: Water Fountain

Click on the image below to go to the instructions for this week's project

water Fountain Project

Back to Top


Next Class: 11. Building Shortcuts

Previous Class: 9. Introduction To Sculpties

Back to Top