Butterflies, part 1

Butterflies don’t fly at night, have you noticed?  Lots of builders just rez some and leave it at that.  Let’s see if we can get some realism.

I’ll wait while you go and buy some butterflies to play with from this marketplace listing.  They’re only L$10…

Got them?  Good.  Once you unbox them you will see they are copy, modify, no transfer.  This is exactly what we want as we can add scripts to them and rez them to our hearts content.

There are three different types in the box, and we are going to rez them one by one, add a script to them, and take them back into our inventory with a different name so we know which ones are ours.

Here’s the script we are going to add to them:

integer g_chan;

default {

    on_rez (integer chan) {
        g_chan = chan;
        llListen (chan, "Butterfly rezzer", NULL_KEY, "");
    }

    listen (integer chan, string name, key id, string msg) {
        if (chan == g_chan) {
            if (msg == "SWAT!") {
                llDie ();
            } else {
                llSetRegionPos ((vector)msg);
            }
        }
    }
}

Let’s examine what this does.  On rez, we get the integer that our rezzer passed us and listen to the rezzer on that channel.  When we receive a message from the rezzer, we delete ourselves if the message is “SWAT!”, else we interpret the message as a position in region co-ordinates and set our position there.  Pretty straightforward, right?

Create a new script in your inventory (probably in the folder you have the butterflies in) and call it something like “Butterfly listener”.  Then, rez each butterfly object, edit it, and drag the script into it.  Editing these can be a little tricky, so use area search to find and edit them.

Here’s a screen shot showing one set of butterflies rezzed with the new script in them.

Name the butterfly objects “butterflys1”, “butterflys2”, and “butterflys3” either while you’re editing them or when you take them back into your inventory.  Note I’ve chosen to keep the creator’s spelling mistake as this makes them easier to find lol.  Note that all lower case is important!  If you don’t name them exactly this, tomorrow’s script won’t work.  You can see them in my inventory window in the above photo.

Tomorrow, we’ll examine the rezzer script, the control notecard, and how to put it all together.  Say tuned!