Jump to content

Can anyone read this understand it?


steph Arnott
 Share

You are about to reply to a thread that has been inactive for 3879 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

My sister has started to learn LSL and this is what she first got to learn with.

showtime(string message)
{
    return; // <--- return inactivates the three lines below this one, up to the bracket
    string line=message+" at "+(string)llFloor(llGetTime());
    L=[line]+llList2List(L,0,9);
    llSetText(llDumpList2String(L,"\n"),<1,1,1>,1);    
}


list buttons=[

" ",            "kill bug",     "particles",
"choose avi",   "green",        "call bug",
"glow on",      "glow off",     "send2 takni",
"visible",    "half invisible", "rez bug"

];
 

do_menu(key user, string m)
{
        if(" "==m)return;
        
        if("glow on"==m)
        {
            glow(0.1, ALL_SIDES);
        }
        
        else if("glow off"==m)
        {
            glow(0, ALL_SIDES);
        }
        
        else if("red"==m)
        {
            llSetColor(<1,0,0>, ALL_SIDES);
        }
        
        else if("white"==m)
        {
            llSetColor(<1,1,0>, ALL_SIDES);
        }
        
        else if("blue"==m)
        {
            llSetColor(<1,0,1>, ALL_SIDES);
        }
        
        else if("green"==m)
        {
            llSetColor(<0,1,0>, ALL_SIDES);
        }
        
        else if("visible"==m)
        {
            llSetAlpha( 1 , ALL_SIDES);
        }
        
        else if("half invisible"==m)
        {
            llSetAlpha( 0.5 , ALL_SIDES);
        }
        
        else if("rez bug"==m)
        {
            showtime("trying to rez bug");
            vector rezpoint=
                llGetPos()
                + <1,llFrand(2)-1,0>
                * llAxisAngle2Rot(<0,0,1>,PI_BY_TWO*(integer)llFrand(4));
            llRezAtRoot("bug",rezpoint,<0,0,0>,<0,0,0,1>,bugchannel);
        }
        
        else if("kill bug"==m)
        {
            llRegionSay(bugchannel,llList2CSV(["die"]));
        }
        
        else if("send2 takni"==m)
        {
            showtime("sending the bugs to takni");
            llRegionSay(bugchannel,llList2CSV(["goto",takni]));
        }
        
        else if("particles"==m)
        {            
            llRegionSay(bugchannel,llList2CSV(["particles"]));
        }
        
        else if("call bug"==m)
        {
            llRegionSay(bugchannel,llList2CSV(["comeback"]));
        }        
        
        else if("choose avi"==m)
        {
            look_for_avatars();
            llOwnerSay((string)llGetListLength(avatars)+" avatars found");
            llDialog(user,"choose an avi to bug:",["BACK"]+names,menuchannel);
            llSetTimerEvent(timeout);         
            return;
        }
        
        else if("BACK"==m)
        {

        }
        
        else if (~(avatar_number=llListFindList(names,[m]))) 
        {
            llOwnerSay("user clicked avatar name ["+m+"] which is avatar number "+(string )avatar_number);    
            // tell all bugs to go to that avi
            llRegionSay(bugchannel,llList2CSV(["goto",llList2Key(avatars,avatar_number)]));
        }
        
        else 
        { 
            llOwnerSay ("MEH, i don't know what to do with ["+m+"]") ;
            return;
        }

        llSetTimerEvent(timeout);        
        llDialog( user ,"choose: ",buttons,menuchannel);
}


integer avatar_number;

key takni="";

integer bugchannel;

list L; 

float timeout=300;


list avatars;

look_for_avatars()
{
    showtime("starting parcel scan");
    list L=llGetAgentList(AGENT_LIST_PARCEL_OWNER,[]); 
    integer i=-llGetListLength(L);
    vector here=llGetPos();
    list A;   
    while(i)   
    {
        key avatar=llList2Key(L,i++);   
        vector avatarpos=posof(avatar);
        A+=[llVecDist(avatarpos,here),avatar]; // save distance to avatar, and key
    }
    A=llListSort(A,2,1); // sort in increasing order of distance
    A=llList2List(A,0,21); // keep only the nearest eleven avatars (we only have 11 menu buttons free)
    A=llDeleteSubList(A,0,0); // erase first number in list
    avatars=llList2ListStrided(A,0,-1,2); // keep only every other entry in list -- that is avatar keys
    i=-llGetListLength(avatars);
    showtime((string)(-i)+" avatars found");
    // now make a list of shortened names to use as menu buttons
    names=[];
    while(i)names+=llGetSubString(shorten(llKey2Name(llList2Key(avatars,i++))),0,12);
    showtime((string)llGetListLength(avatars)+" avatars found ");    
}

list names;

integer menuchannel;

string shorten(string name)
{    
    if(llGetSubString(name,-9,-1)==" Resident")
    {
        return llDeleteSubString(name,-9,-1);
    }
    return name;
}

integer listencontrol;


glow(float g, integer face){    llSetLinkPrimitiveParamsFast(-4,   [PRIM_GLOW,face,g]);    }


vector posof(key k){    return llList2Vector(llGetObjectDetails(k,[OBJECT_POS]),0);}

default
{
    on_rez(integer whatever) // reset script so it doesnt get same menuchannel number as other copies
    {
        llResetScript();
    }
    
    state_entry()    
    {
        llSetText("",<1,1,1>,1);
        showtime("start");
        bugchannel= -1000000 - (integer)llFrand(2e9) - (integer) llFrand(5e5) ;
        menuchannel = - (integer) llFrand(2e9)- (integer) llFrand(5e5) - 5456 ;
                                    
        showtime( "menuchannel set to "+ (string) menuchannel );
        showtime( "bugchannel set to "+ (string) bugchannel );
        
        listencontrol = llListen(menuchannel,"","","");
        llListenControl(listencontrol,0);        
    }
    
    timer()
    {
        showtime("timer()");
        
        llListenControl(listencontrol,0);        
        llSetTimerEvent(0);        
    }

    touch_start(integer nevermind)
    {
        showtime("click");
        
        llListenControl(listencontrol,1);        
        llSetTimerEvent(timeout);
        llDialog(llDetectedKey(0),"choose: ",buttons,menuchannel);
    }
    
    listen (integer chan, string name, key user, string m)
    {
        showtime("user pressed ["+m+"]");
        do_menu(user, m);                
    }
    
    object_rez(key obj)
    {
        showtime("bug rezzed");
        showtime("uploading script to bug");        
        llRemoteLoadScriptPin(obj,"! bug script",1111,1,bugchannel);
        showtime("uploading done");                
    }
}

 

Link to comment
Share on other sites

My sister has started to learn LSL and this is what she first got to learn with.

showtime(string message)
{
    return; // <--- return inactivates the three lines below this one, up to the bracket
    string line=message+" at "+(string)llFloor(llGetTime());
    L=[line]+llList2List(L,0,9);
    llSetText(llDumpList2String(L,"\n"),<1,1,1>,1);    
}


list buttons=[

" ",            "kill bug",     "particles",
"choose avi",   "green",        "call bug",
"glow on",      "glow off",     "send2 takni",
"visible",    "half invisible", "rez bug"

];
 

do_menu(key user, string m)
{
        if(" "==m)return;
        
        if("glow on"==m)
        {
            glow(0.1, ALL_SIDES);
        }
        
        else if("glow off"==m)
        {
            glow(0, ALL_SIDES);
        }
        
        else if("red"==m)
        {
            llSetColor(<1,0,0>, ALL_SIDES);
        }
        
        else if("white"==m)
        {
            llSetColor(<1,1,0>, ALL_SIDES);
        }
        
        else if("blue"==m)
        {
            llSetColor(<1,0,1>, ALL_SIDES);
        }
        
        else if("green"==m)
        {
            llSetColor(<0,1,0>, ALL_SIDES);
        }
        
        else if("visible"==m)
        {
            llSetAlpha( 1 , ALL_SIDES);
        }
        
        else if("half invisible"==m)
        {
            llSetAlpha( 0.5 , ALL_SIDES);
        }
        
        else if("rez bug"==m)
        {
            showtime("trying to rez bug");
            vector rezpoint=
                llGetPos()
                + <1,llFrand(2)-1,0>
                * llAxisAngle2Rot(<0,0,1>,PI_BY_TWO*(integer)llFrand(4));
            llRezAtRoot("bug",rezpoint,<0,0,0>,<0,0,0,1>,bugchannel);
        }
        
        else if("kill bug"==m)
        {
            llRegionSay(bugchannel,llList2CSV(["die"]));
        }
        
        else if("send2 takni"==m)
        {
            showtime("sending the bugs to takni");
            llRegionSay(bugchannel,llList2CSV(["goto",takni]));
        }
        
        else if("particles"==m)
        {            
            llRegionSay(bugchannel,llList2CSV(["particles"]));
        }
        
        else if("call bug"==m)
        {
            llRegionSay(bugchannel,llList2CSV(["comeback"]));
        }        
        
        else if("choose avi"==m)
        {
            look_for_avatars();
            llOwnerSay((string)llGetListLength(avatars)+" avatars found");
            llDialog(user,"choose an avi to bug:",["BACK"]+names,menuchannel);
            llSetTimerEvent(timeout);         
            return;
        }
        
        else if("BACK"==m)
        {

        }
        
        else if (~(avatar_number=llListFindList(names,[m]))) 
        {
            llOwnerSay("user clicked avatar name ["+m+"] which is avatar number "+(string )avatar_number);    
            // tell all bugs to go to that avi
            llRegionSay(bugchannel,llList2CSV(["goto",llList2Key(avatars,avatar_number)]));
        }
        
        else 
        { 
            llOwnerSay ("MEH, i don't know what to do with ["+m+"]") ;
            return;
        }

        llSetTimerEvent(timeout);        
        llDialog( user ,"choose: ",buttons,menuchannel);
}


integer avatar_number;

key takni="";

integer bugchannel;

list L; 

float timeout=300;


list avatars;

look_for_avatars()
{
    showtime("starting parcel scan");
    list L=llGetAgentList(AGENT_LIST_PARCEL_OWNER,[]); 
    integer i=-llGetListLength(L);
    vector here=llGetPos();
    list A;   
    while(i)   
    {
        key avatar=llList2Key(L,i++);   
        vector avatarpos=posof(avatar);
        A+=[llVecDist(avatarpos,here),avatar]; // save distance to avatar, and key
    }
    A=llListSort(A,2,1); // sort in increasing order of distance
    A=llList2List(A,0,21); // keep only the nearest eleven avatars (we only have 11 menu buttons free)
    A=llDeleteSubList(A,0,0); // erase first number in list
    avatars=llList2ListStrided(A,0,-1,2); // keep only every other entry in list -- that is avatar keys
    i=-llGetListLength(avatars);
    showtime((string)(-i)+" avatars found");
    // now make a list of shortened names to use as menu buttons
    names=[];
    while(i)names+=llGetSubString(shorten(llKey2Name(llList2Key(avatars,i++))),0,12);
    showtime((string)llGetListLength(avatars)+" avatars found ");    
}

list names;

integer menuchannel;

string shorten(string name)
{    
    if(llGetSubString(name,-9,-1)==" Resident")
    {
        return llDeleteSubString(name,-9,-1);
    }
    return name;
}

integer listencontrol;


glow(float g, integer face){    llSetLinkPrimitiveParamsFast(-4,   [PRIM_GLOW,face,g]);    }


vector posof(key k){    return llList2Vector(llGetObjectDetails(k,[OBJECT_POS]),0);}

default
{
    on_rez(integer whatever) // reset script so it doesnt get same menuchannel number as other copies
    {
        llResetScript();
    }
    
    state_entry()    
    {
        llSetText("",<1,1,1>,1);
        showtime("start");
        bugchannel= -1000000 - (integer)llFrand(2e9) - (integer) llFrand(5e5) ;
        menuchannel = - (integer) llFrand(2e9)- (integer) llFrand(5e5) - 5456 ;
                                    
        showtime( "menuchannel set to "+ (string) menuchannel );
        showtime( "bugchannel set to "+ (string) bugchannel );
        
        listencontrol = llListen(menuchannel,"","","");
        llListenControl(listencontrol,0);        
    }
    
    timer()
    {
        showtime("timer()");
        
        llListenControl(listencontrol,0);        
        llSetTimerEvent(0);        
    }

    touch_start(integer nevermind)
    {
        showtime("click");
        
        llListenControl(listencontrol,1);        
        llSetTimerEvent(timeout);
        llDialog(llDetectedKey(0),"choose: ",buttons,menuchannel);
    }
    
    listen (integer chan, string name, key user, string m)
    {
        showtime("user pressed ["+m+"]");
        do_menu(user, m);                
    }
    
    object_rez(key obj)
    {
        showtime("bug rezzed");
        showtime("uploading script to bug");        
        llRemoteLoadScriptPin(obj,"! bug script",1111,1,bugchannel);
        showtime("uploading done");                
    }
}

 

Link to comment
Share on other sites

Put the script in a box in world and click on the box. you will se a menu popup. You need to make a bug object and such to make the script work fully and a script in the bug object..

Most scripters can read and understand it. Keep up the practice and it will start making sense as you see what and how the script works and the actions it produces

The list buttons will be what shows on the popup menu dialog

list buttons=[" ",            "kill bug",     "particles","choose avi",   "green",        "call bug","glow on",      "glow off",     "send2 takni","visible",    "half invisible", "rez bug"


Lots to learn. You can also find help in the secondlife wiki in the scripting section. Depends on what instructions she got to do with the script. There should be a bug script to put in the bug object

Link to comment
Share on other sites

Abolutely Steph.  I'd just finished reading through it as you posted the above.  Apart from being way too long and complicated for a newbie script it would help if it were better written - simple things such as having all the global variable definitions in one place (at the top!) for instance.  I thought the "L" mentioned in showtime() was missing until I read more carefully.

On the other hand ... If this is being used as part of a guided class the instructor can walk through it and, presumably, explain other/better ways to do the same thing.

It is a pity though that beginners are being taught to bug people!

ETA for below: "list L" is declared a few lines above look_for_avatars().  The timer uses llListenControl() to turn the listen off.

Link to comment
Share on other sites

It seems to be two scripts, cobbled together rather, for some sort of object that glows, vanishes and so on, according to menu commands, and also rezzes some sort of bugs (followers?) that it presumably sends after selected avatars, though we don't know what the items do when they're rezzed because we haven't got the script to go with them.

I don't understand this showtime function (which is deactivated anyway, by the return; right at the begining (does that compile -- dead code that can't be reached in a user function?).   I can see what it's supposed to do, but in the script it looks as if the scripter expects it to generate a menu by some mysterious manner that I can't fathom.

 

Link to comment
Share on other sites

This is the second script.

integer nowparticling;list L;showtime(string message){   return;    L=[message+" "+(string)llFloor(llGetTime())]+llList2List(L,-19,-1);    llOwnerSay( message+" "+(string)llFloor(llGetTime()) );    llSetText(llDumpList2String(L,"\n"),<1,1,1>,1);    }key target;key nullkey;integer channelnumber;vector posof(key k){    return llList2Vector(llGetObjectDetails(k,[OBJECT_POS]),0);}integer h;docommand(string m){    list L=llCSV2List(m);    string cmd=llList2String(L,0);        showtime("docommand "+cmd);        if("goto"==cmd)    {        target=llList2Key(L,1);        vector v=posof(target);                    if(v)        {                                llOwnerSay("now annoying "+llKey2Name(target));            llSetRegionPos(v);                        llListenRemove(h);            h=llListen(0,"",target,"");            llSetTimerEvent(3);                    }        else         {            target=nullkey;            llSetTimerEvent(0);            llOwnerSay("sorry, target poofed");        }    }        else if("die"==cmd)    {        llDie();    }        else if("comeback"==cmd)    {        vector v=posof(llGetOwner());        if(v)        {            llSetTimerEvent(0);            llSetRegionPos(v);            }        else llDie();    }    else if("particles"==cmd)    {        if(target)        {            nowparticling=1;            llResetTime();//            else target=nullkey;                }    }}default{    state_entry()    {        llSetRemoteScriptAccessPin( 1111 );        showtime("script started");        llSitTarget(<0,0,1>,<0,0,0,1>);        channelnumber=llGetStartParameter();        showtime("channelnumber is "+(string)channelnumber);                if(channelnumber)        {            state working;                    }    }        /*    on_rez(integer x)    {        llResetTime();        showtime("rezzed");        channelnumber=x;        if(x)state working;    }    */}state working{    state_entry()    {        showtime("working started");        llListen(channelnumber,"","","");    }        listen(integer c, string n, key k, string m)    {        showtime("heard "+llGetSubString(m,0,2));        if(channelnumber==c)docommand(m);        else llOwnerSay(n+" said "+m);    }    timer()    {        if(nowparticling)        {            vector v=posof(target);                        if(v)            {                vector offs=2*llVecNorm(<llFrand(4)-2,llFrand(4)-2,llFrand(2)>);                llSetRegionPos(v-offs+<0,0,1>);                llSetRot(llRotBetween(<0,0,1>,offs));                llMessageLinked(LINK_THIS,1,"shortbeam","2");                if(llGetTime()>14)                {                    nowparticling=0;                    llMessageLinked(LINK_THIS,0,"shortbeam","");                    llSetRot(<0,0,0,1>);                                    }            }            else llDie();            return;                    }        if(target)        {            vector offset=<1,0,0>*llAxisAngle2Rot(<0,0,1>,llFrand(6.3));                    llSetRegionPos(posof(target)+offset);        }            else llSetTimerEvent(0);            }}

 the bug script is just a partical and a 3 min kill script. At lrast i can read this one, lol

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3879 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...