Wednesday, October 1, 2014

Simple Timer [Level II]

Timers are essential tools. We need them for a variety of reasons--- to play sounds or make particles at specified intervals, to time out blue menus, to stop prims from listening (and save server resources), or to pace changes in a prim's position or characteristics.

It's possible to use multiple timers (and I will eventually write about this), but for now, here's an annotated script that will play a click sound at a specified interval after the prim has been touched.

Saturday, September 13, 2014

Hovering Text [Level 1]



Hovering or floating text is that sometimes annoying lettering that appears above (and sometimes in front of) a prim.

Hovering text can be any color, can be broken into multiple lines, and can be solid or transparent. Messages are limited to 254 bytes. The distance at which hover text can be viewed is dependent upon the size of the prim. Bigger equals visibility at a longer distance.

Hovering text is set by a script, and will remain even if the script is removed from a prim. The Scrubber script I shared will remove it, or, if the script is still in the prim, you can remove the text between quotation marks in the llSetText line so it reads "". The official way to remove hover text, however, is with the line that follows:

Use Scratch's Move Functions in Your Own Script (Level III)

A function in LSL is essentially a series of directions specified by the user and given a name. Functions are placed at the beginning of the script and can be easily called when needed.


The movement functions in the Scratch program can turn and move a prim easily. All you do is call a function and tell it how far to move.


Below the fold you'll find the script with the various Scratch functions. Your prim will move in a variety of ways as it illustrates what the functions do.

Friday, September 12, 2014

Loops [Level III]

I had the devil of a time figuring out how to create a loop in LSL.

A loop, by the way, is a process which repeats as a variable increments until it reaches a pre-determined level. It's like saying "So this ten times," or "Count to 20."

In BASIC, in which I am proficient, it was easy to create a loop. It was, as I recall (it's been many years), like this:

10 FOR k = 1 TO 10;
20 SAY k;
20 NEXT;

This would cause the numbers 1 to 10 to appear on the screen, one number per line.

I just couldn't figure out how to do it in Second Life.

It was the MIT LSL scripting program Scratch that saved me. By looking at the code generated when I asked the script to do something X times, I was able to extract a simple loop. Here it is.


Thursday, September 11, 2014

Scratch for Second Life [Level II]


Finding Scratch for Second Life was huge for me. It enabled me to move prims nonphysically, something I had been trying and failing to do.

Scratch does a lot more than move prims, however.

Scratch is a program developed by Eric Rosenbaum at at the MIT Media Lab. In essence, it's a programming language that allows you to build a script by assembling modules which are respresented as blocks. When you're finished, Scratch will generate code which you then paste into a script inside your prim.

To use Scratch, watch the three-minute tutorial, then download and run the small program and start moving blocks about. It will take you only a few minutes to create your first Scratch script.

Scratch doesn't do everything one can do with LSL, but it can do quite a lot. Here are its functions:

Moving Prims

  • Move prims forward or backward X meters.
  • Turn prims X degrees left or right
  • Move up or down X meters
  • Roll plus or minus X degrees
  • Pitch plus or minus X degrees
  • Point toward nearest avatar
  • Point toward owner of prim
  • Point in direction X

This allows you to turn a prim and move it in any direction. Movement is limited to ten meters, but it's easy to do sequential movements.

Control

  • Respond to touch
  • Respond to collision
  • Respond when rezzed
  • Respond to chat
  • Wait X seconds
  • Repeat an action X times
  • Broadcast (Say things)
  • Respond differentially using if and else

Looks

  • Say
  • Set hover text to specified color
  • Change color by X amount
  • Set color to specified vector
  • Set level of transparency
  • Change size of linkset by plus or minus X percent

Sound

  • Play sound from Script's short list of sounds
  • Play your own sound

Sensing

  • Determine distance to nearest avatar
  • Determine distance to owner
  • Determine number of avatars within range X meters

Numerical Calculations


  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Generate random number between 1 and 10
  • Less than
  • Equal to
  • Greater than

Variables

  • Create or delete a variable

Pen

  • Clear
  • Pen down
  • Pen up
  • Change pen color by X amount
  1. Set pen color to X

The pen requires a scripted prim called lineSegment. I don't remember how I acquired mine, but it's full perm and I'll be happy to pass a copy to you. Just IM me in world or drop me a notecard.


Fireflies [Level II]

In my early days in Second Life I picked up a free full-perm lightning bug script by Ama Omega; its name was Foxfire.

The script was set to turn fireflies on at sundown and off when the sum came back up. I managed to change that so they were active 24/7.

As fireflies go, Ama's weren't bad, but Sweetie (a recurring character in Chey's Second Life Blog)       wanted to tweak them. Fireflies she said, weren't yellow, but yellow-green. These didn't stay on quite long enough-- and they were too dense and not quite wide-ranging enough. And oh, yes, didn't fireflies come out only at night/ Why did these flash all day?

I had her apply color to a prim and, by doing some calculations, soon had the script making fireflies of the same shade. With Sweetie over my shoulder, I tweaked the script, making the flashes last a little longer, thinning the field of fireflies, and dispersing them over a wider range. Then I stayed online through a full four-hour Second Life day cycle and discovered just the right moment to turn them on (real life fireflies start just as its dusk). Real life fireflies stop flashing after a few hours, but I conveniently ignored that fact of biology and turned them off when the sum was just above the horizon. Then we spent an evening walking around Whimsy finding the old fireflies and replacing them with the new ones. Using beacons made that relatively easy. Here's my post about the process.

Below you'll find my modified firefly script, and below that Ama's original Foxfire Script. Ama did a great job, but I think you'll find my tweaks make for a nicer effect.

You can drop the script into rocks, trees, or just about anywhere. Fireflies will come out as it begins to grow dark and disappear before it's fully light. Please note, The fireflies are responding to the Second Life day cycle on your sim, and not to your viewer setting of midday, morning, evening, or midnight.

Tuesday, September 2, 2014

Thursday, August 14, 2014

The Scrubber [Level I]

It can be annoying when you have a prim that makes a sound you can't turn off, or produces particles you can't turn off, or has a sit position you can't turn off, or has a texture animation or an omega rotation you can't turn off. Even if the script is removed, the prim's behavior persists. It can drive you crazy.

The Scrubber is a handy script that rids a prim of just about any residual effect of previous scripts and then handily deletes itself. You just open the Edit window, click the Content tab, drag the script from inventory, let go of it, and it does its work in seconds.

About This Blog

Scripting in Second Life is made difficulty by the arcane Linden Scripting Language and even more by the unwillingness of most coders to share their knowledge or their scripts It's as if it becomes double-secret need-to-know if the modify a single line.

My purpose in this blog is to share what I have learned about scripting in Second Life and provide you with free full-permission scripts to use as you wish. I ask only that you not charge others for them unless you significantly modify them. By significantly I mean you add functionality to the script-- not just change variables or chat messages.

Much of the work will be mine. Some of it is in the public domain. When that is so and when I know the author, I will acknowledge the author(s) in text and in the code of the scirpt.

On this blog I will describe scripts and paste the LSL code for you to copy and put in your own prims.  Some scripts will be simple, and some quite complex. I hope there will be something for anyone who wishes to make prims misbehave.

I have dedicated a portion of my Flights of Fancy store to providing scripts in world. Go here to visit my store and here to teleport directly to the scripting area. If you visit shortly after I post this, don't be surprised if there's not much there. There will be more later, I assure you.