YaK:: Automated Rezzing in Second Life [Changes]   [Calendar]   [Search]   [Index]   [PhotoTags]   

Automated Rezzing in Second Life

Linden Scripting Language (LSL) is ideosyncratic and often doesn't do what you think it is going to do.

Evolve your scripts in baby steps, testing one new thing at a time, with very small cases instead of large loops. Especially with the following example that rezzes the Pacman Spots in The Kingdom of Yaknetistan in Second Life -> "Bedstraw (128, 128)".

Two objects are used in this case: an Auto Rezzer Box (pull it from your inventory when you need it, Touch it to run it, then Delete it) and a Payload object, the prototype to be rezzed. Set the "Tempoary" bit on your payload object while you debug! The Payload must be dragged into the Contents box of the Rezzer Box. The rezzer should physically be at a high location from which there is a direct line (not going underground) to where each new object will be placed.

The Rezzer has the following script. It does its work when touched. It can only send objects to integer coordinates, centered at exactly ground level. (So on average, half of each pacman spot is underground). Notice the infinite-loop safety valve named "max", the hardcoded coordinates, and payload contents name "Payload-PacmanSpot". The bitshifting ((x<<8)+y) takes the target coordinates (x,y) -- which must each be in the range [1,255] -- and encodes them into a single integer parameter, which the rezzed object receives (it receives 0 if you pull it from your inventory, a special case.)

vector pos;
integer max;

Make(integer x, integer y)
    llRezObject("Payload-PacmanSpot", pos, <0,0,0>, <0,0,0,0>, (x<<8) + y);
    max = max - 1;
    if (max<1) { llSleep(99999999); }  // infinite loop trap

    touch_start(integer total_number)
        pos= llGetPos();
        llSay(0, "Touched at " + (string)pos );

        integer x;
        integer y;

        max= 200;

        // Yurt Lane
        for (x=176+4; x<248; x=x+8) { Make(x,96+4);}
        // North Ave
        for (x=88+4; x<168; x=x+8) { Make(x,136+4);}
        // South Perimeter
        for (x=8+4; x<192; x=x+8) { Make(x,0+4);}
        for (x=224+4; x<248; x=x+8) { Make(x,0+4);}
        // North Perimeter
        for (x=32+4; x<128; x=x+8) { Make(x,248+4);}
        // East Perimeter
        for (y=0+4; y<136; y=y+8) { Make(248+4,y);}
        // East Ave
        for (y=8+4; y<144; y=y+8) { Make(168+4,y);}
        // West Blvd
        for (y=8+4; y<144; y=y+8) { Make(80+4,y);}
        // West Perimeter
        for (y=144+4; y<240; y=y+8) { Make(0+4,y);}

Then the following script goes in the Payload object. It activates when the object is rezzed, and tries to move the object to the target coordinates (received encoded as the integer a), or until the object fails to move for some reason.

object_move_to(vector position) {
    vector last;
    do {
        last = llGetPos();
    } while ((llVecDist(llGetPos(),position) > 0.001) && (llGetPos() != last));

    on_rez(integer a)
        if (a)
            llListen(123456, "", NULL_KEY, "");

            integer x= (a>>8)&255;
            integer y= (a&255);
            float ht= llGround(<x, y, 0.0>);
            object_move_to( <x, y, ht> );

    listen(integer channel, string name, key id, string message)

Notice the rezzed object is listening on a secret channel number 123456. When any message is spoken (or whispered or shouted) on that channel, the rezzed object will die. This is very important, both for cleaning up after mistakes, and for deleting the existing objects when you change your rezzing script and want to run it again.

Caution: Please read and try to understand these scripts before you start on your own. It's easy to make a difficult mess to clean up. I've done it (:

References on LSL

Snags in sharing rezzers: The rezzer, the payload, and both scripts must each be set to "share with group"; next owner can modify; whatever. If you don't get all of them set, future owners will not be able to use/modify them.

(unless otherwise marked) Copyright 2002-2014 YakPeople. All rights reserved.
(last modified 2007-01-08)       [Login]
(No back references.)