Don't click here unless you want to be banned.

LSL Wiki : ExampleSelfReplication

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org
This is an very basic self-replicating script. It has a 'Time To Live' (ttl) counter, which ensures that the object won't keep replicating.

This example shows uses of the llGiveInventory and llRezObject functions as well as the object_rez, on_rez and changed events.

Please note that a ttl mechanism is nowhere near enough for a 'real' script!

See the page on self replication for more info about fail-safing and an assortment of amusing moral stories.

Basic steps

- Create a prim, call it 'rezTest'
- Add this script to it
- Take a copy and put in into the inventory of the first object
- Touch the first object

// The ttl variable is a counter, decreased for each subsequent replication,
// the child that get rezzed with a ttl value of zero will not procreate.

integer ttl = 3;


rez_child()
{
    // Check if we're allowed to create any more offspring
    if(ttl > 0)
    {
        // Offspring ttl should be one closer to zero
        integer ttl_child = ttl - 1;

        // Rez child one meter above me
        llRezObject("rezTest", llGetPos()+<0.,0.,1.>, <0.,0.,0.>, <0.,0.,0.,0.>, ttl_child);
    }
}

default
{
    // If you touch me, we'll have babies!
    touch_start(integer total_number)
    {
        rez_child();
    }
 
    // llRezObject throws event object_rez on the parent with the offspring as parameter   
    object_rez(key child) 
    { 
        // Give copy of child to child
        llGiveInventory(child, llKey2Name(child)); 
    } 
    
    // When rezzed, the event on_rez is called on me as the child
    on_rez(integer ttl_in)
    {
        // Save child (this one) ttl;
        ttl = ttl_in;
    }

    // Because of the script-delay we have to connect the grand-child rezzing 
    // to the 'changed' event, which happens when someone (the parent) has
    // given me (as the child) something (a copy of myself)
    changed(integer change)
    {
        if(change == CHANGED_INVENTORY)
        {
            rez_child();        
        }
    }
}


Here is an easier to understand example...

default
{
touch_start ( integer NUMBER )
{
llRezObject ( "Object", < 0., 0., 1. >, ZERO_VECTOR, ZERO_ROTATION, 0 );
}

object_rez ( key ITEM )
{
llGiveInventory ( ITEM, llKey2Name ( ITEM ) );
}
}

Hope it helps clear this up ...Moira Willenov.
Comments [Hide comments/form]
This code is rather confusing. Could you possibly use some variable name other than ttl?
-- KeknehvPsaltery (2005-07-18 10:25:10)
No, but it's a wiki - be my guest!
-- StefanNilsson (2005-07-19 11:22:50)
For some reason I can't help but think tribbles.. Hmm.. What would happen if you removed the offspring limitations and changed it so that the child rezed a child on rez? Hmm.. maybe we could also be evil and place it spiraling outward. Orr hmm a double helix.. yeah..
/me runs goes does that.
-- Vector010 (2006-02-27 09:49:59)
hmm i think ill try it when ive been scripting more then a month. lol.
-- Turnni1 (2007-01-13 07:16:32)
What "first object" ???
-- cpe-24-193-95-169.nyc.res.rr.com (2007-04-12 00:33:54)
Attach a comment to this page: