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 "Do 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 sun 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 at 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.