Tuesday, December 02, 2008
USERLOGIN PASSWORD Remember?
You are here » Learning Center ยป Forums

Openlife Forums

 Openlife Grid Forums
Minimize
 
  Openlife Forums  Scripting  LSL Discussion  Testing script LS vs OG
Previous Previous
 
Next Next
New Post 5/3/2008 12:43 PM
User is offline Elsja Vacano
58 posts
Openlife Apprentice




Testing script LS vs OG 

Scrit for SL

loop2detect(string szWhy,integer iNum) {
    key idKey;
    integer iTmp;
       
    for(iTmp=0;iTmp<iNum;iTmp++) {
        idKey=llDetectedKey(iTmp);
        llOwnerSay(szWhy+" with "+llKey2Name(idKey));
    }
}

loopFromCollision(string szWhy,integer iNum) {
    key idKey;
    integer iTmp;
       
    for(iTmp=0;iTmp<iNum;iTmp++) {
        idKey=llDetectedKey(iTmp);
        llOwnerSay(szWhy+" with "+llKey2Name(idKey)+" belonging to "+llKey2Name(llGetOwnerKey(idKey)));
    }
}

newlocation(string szEvent) {
    llOwnerSay("I am now at "+(string)llGetPos()+" with a rot of "+(string)llGetRot()+" because event "+szEvent);
}

rezObject() {
    integer iNum=llGetInventoryNumber(INVENTORY_OBJECT);
    while(iNum) { // rez by the end to win a variable
        string szObject=llGetInventoryName(INVENTORY_OBJECT,--iNum); // match the last object with its pos first
        // param is a random number != 0 to make the difference by the 0 from Inventory rezing
        llRezObject(szObject, llGetPos() + <0.0, 0.0, 0.5>, ZERO_VECTOR, ZERO_ROTATION,(integer)llFrand(30)+1);
    }
}

default
{
    state_entry() {
        llSay(0, "Hello, Avatar!");
        //needed for llAvatarOnSitTarget to work. The vectors components must not all be set to 0
        llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION);
        llOwnerSay("I start with the parameter "+(string)llGetStartParameter());
        llListen(PUBLIC_CHANNEL,"",llGetOwner(),""); // hear public channel to trigger listen event
    }
    moving_start() { newlocation("moving_start"); }          
    moving_end() { newlocation("moving_end"); }          
    on_rez(integer iParam) {
        llOwnerSay("on_rez with param="+(string)iParam);
        llOwnerSay("Be care I act it the state of the object is when taken");
    }
    listen(integer iChan,string szName,key id,string szMsg)  {
        llOwnerSay("Listen Event:"+(string)iChan+" "+szName+" id="+(string)id+" says "+szMsg);
    }
    touch_start(integer iNum) { loop2detect("Touch_start",iNum); }
    touch(integer iNum) { loop2detect("Touch",iNum); }
    touch_end(integer iNum) { loop2detect("Touch_end",iNum); }
    collision_start( integer iNum ) { loopFromCollision("collision_start",iNum); }
    collision( integer iNum ) { loopFromCollision("collision",iNum); }
    collision_end( integer iNum ) { loopFromCollision("collision_end",iNum); }
    changed(integer iFlag) //reset script if inventory iFlags
    {
        llOwnerSay("Change event with "+(string)iFlag);
        //note that it's & and not &&... it's bitwise!
        if (iFlag & CHANGED_INVENTORY) {
            llOwnerSay("The inventory has changed.");
            rezObject();
        }
        if (iFlag & CHANGED_COLOR) llOwnerSay("The color or alpha changed.");
        if (iFlag & CHANGED_SHAPE) llOwnerSay("The prims shape has changed.");
        if (iFlag & CHANGED_SCALE) llOwnerSay("The prims size has changed.");
        if (iFlag & CHANGED_TEXTURE) llOwnerSay("The prims texture or texture attributes have changed.");
        if (iFlag & CHANGED_LINK) {
            key idAvatar;
            idAvatar=llAvatarOnSitTarget();
            llOwnerSay("The number of links have changed.");
            llOwnerSay("The avatar sitting is "+llKey2Name(idAvatar)+" with id="+(string)idAvatar);
        }
        if (iFlag & CHANGED_ALLOWED_DROP)
            llOwnerSay("The inventory has iFlagd as a result of a user without mod permissions dropping an item on the prim and it being allowed by the script.");
        if (iFlag & CHANGED_OWNER) llOwnerSay("The owner of the object has changed.");
        if (iFlag & CHANGED_REGION) llOwnerSay("The region the object is in has changed.");
        if (iFlag & CHANGED_TELEPORT) llOwnerSay("The object has been teleported while attached.");
    }
    attach(key idUser) { llOwnerSay("Attach on "+llKey2Name(idUser)); }
    money(key id,integer iAmount) {
        llOwnerSay("Get "+(string)iAmount+" L$ from "+llKey2Name(id));
        llOwnerSay("Fictive refund of "+(string)iAmount+" L$ from "+llKey2Name(id));
        llOwnerSay("Put this script twice in the box to see how funny it is");
    }
    state_exit() { llOwnerSay("State exit. Seems I cancel all running llListen() llSetTimerEvent"); }
    object_rez(key id) { llOwnerSay("I create the object with id="+(string)id); }
}

I comment all that is not working

loop2detect(string szWhy,integer iNum) {
    key idKey;
    integer iTmp;
       
    for(iTmp=0;iTmp<iNum;iTmp++) {
        idKey=llDetectedKey(iTmp);
        llOwnerSay(szWhy+" with "+llKey2Name(idKey));
    }
}

loopFromCollision(string szWhy,integer iNum) {
    key idKey;
    integer iTmp;
       
    for(iTmp=0;iTmp<iNum;iTmp++) {
    idKey=llDetectedKey(iTmp);
    llOwnerSay(szWhy+" with "+llKey2Name(idKey)+" belonging to "+llKey2Name(llGetOwnerKey(idKey)));
    }
}

newlocation(string szEvent) {
    llOwnerSay("I am now at "+(string)llGetPos()+" with a rot of "+(string)llGetRot()+" because event "+szEvent);
}

//rezObject() {
//    integer iNum=llGetInventoryNumber(INVENTORY_OBJECT);
//    while(iNum!=0) { // rez by the end to win a variable
//        string szObject=llGetInventoryName(INVENTORY_OBJECT,--iNum); // match the last object with its pos first
//        // param is a random number != 0 to make the difference by the 0 from Inventory rezing
//        llRezObject(szObject, llGetPos() + <0.0, 0.0, 0.5>, ZERO_VECTOR, ZERO_ROTATION,(integer)16);
//    }
//}


integer And(integer iA,integer iB) {
    integer iTmp;
    for(iTmp=0;iTmp<32;iTmp+=1) {
        integer iBitA=iA%2;
        integer iBitB=iB%2;
        if(iBitA==iBitB) {
            if(iBitA!=0) return(TRUE);
        }
        iA/=2; // remove the bit for next check
        iB/=2; // remove the bit for next check
    }
    return(FALSE);
}

default
{
    state_entry() {
        llSay(0, "Hello, Avatar!");
        //needed for llAvatarOnSitTarget to work. The vectors components must not all be set to 0
        llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION);
        //llOwnerSay("I start with the parameter "+(string)llGetStartParameter());
        llListen(PUBLIC_CHANNEL,"",llGetOwner(),""); // hear public channel to trigger listen event
    }
    //moving_start() { newlocation("moving_start"); }          
    //moving_end() { newlocation("moving_end"); }          
    //on_rez(integer iParam) {
    //    llOwnerSay("on_rez with param="+(string)iParam);
    //    llOwnerSay("Be care I act it the state of the object is when taken");
    //}
    listen(integer iChan,string szName,key id,string szMsg)  {
        llOwnerSay("Listen Event:"+(string)iChan+" "+szName+" id="+(string)id+" says "+szMsg);
    }
    touch_start(integer iNum) { loop2detect("Touch_start",iNum); }
    touch(integer iNum) { loop2detect("Touch",iNum); }
    touch_end(integer iNum) { loop2detect("Touch_end",iNum); }
    //collision_start( integer iNum ) { loopFromCollision("collision_start",iNum); }
    //collision( integer iNum ) { loopFromCollision("collision",iNum); }
    //collision_end( integer iNum ) { loopFromCollision("collision_end",iNum); }
    changed(integer iFlag) //reset script if inventory iFlags
    {
        llOwnerSay("Change event with "+(string)iFlag);
        //note that it's & and not &&... it's bitwise!
        if (And(iFlag,CHANGED_INVENTORY)!=0) {
            llOwnerSay("The inventory has changed.");
    //        rezObject();
        }
        //if (And(iFlag,CHANGED_COLOR)!=0) llOwnerSay("The color or alpha changed.");
        //if (And(iFlag,CHANGED_SHAPE)!=0) llOwnerSay("The prims shape has changed.");
        //if (And(iFlag,CHANGED_SCALE)!=0) llOwnerSay("The prims size has changed.");
        if (And(iFlag,CHANGED_TEXTURE)!=0) llOwnerSay("The prims texture or texture attributes have changed.");
        if (And(iFlag,CHANGED_LINK)!=0) {
            key idAvatar;
            idAvatar=llAvatarOnSitTarget();
            llOwnerSay("The number of links have changed.");
            llOwnerSay("The avatar sitting is "+llKey2Name(idAvatar)+" with id="+(string)idAvatar);
        }
        if (And(iFlag,CHANGED_ALLOWED_DROP)!=0)
            llOwnerSay("The inventory has iFlagd as a result of a user without mod permissions dropping an item on the prim and it being allowed by the script.");

        if (And(iFlag,CHANGED_OWNER)!=0) llOwnerSay("The owner of the object has changed.");
     //   if (And(iFlag,CHANGED_REGION)) llOwnerSay("The region the object is in has changed.");
    //    if (And(iFlag,CHANGED_TELEPORT)) llOwnerSay("The object has been teleported while attached.");
    }
    //attach(key idUser) { llOwnerSay("Attach on "+llKey2Name(idUser)); }
    //money(key id,integer iAmount) {
    //    llOwnerSay("Get "+(string)iAmount+" L$ from "+llKey2Name(id));
    //    llOwnerSay("Fictive refund of "+(string)iAmount+" L$ from "+llKey2Name(id));
    //    llOwnerSay("Put this script twice in the box to see how funny it is");
    //}
    state_exit() { llOwnerSay("State exit. Seems I cancel all running llListen() llSetTimerEvent"); }
    //object_rez(key id) { llOwnerSay("I create the object with id="+(string)id); }
}

[/quote]

 
New Post 5/4/2008 7:38 PM
User is offline Macca (Ret)
78 posts
Openlife Apprentice


Re: Testing script LS vs OG 

What does it do, how do I use it and why would I want to???


Working towards a red dot. It's all I have for now. [and no, I couldn't just leave]
 
New Post 5/5/2008 1:16 AM
User is offline Elsja Vacano
58 posts
Openlife Apprentice




Re: Testing script LS vs OG 

To Use just create a box and put the script in it.

Play with the box, touch t, resize and so on.

 

I firstly write it for SL, to see what event are generated for a specific action.

It is the way to understood how event works.

 

The two versions show the difference between the way to write script between  SL  and OG.

Writing script make some time and write a script for both grid may be quicker (I do not think this was possible now)

 

The script can be a debugging toll.

Why a script does not work. But code it was wrong? With this script you can see if a event is trigger by the system.

So if the expected even is not generated by the system, you will see it directly withour spend lot of timein debugging the main one.

 

Because the if(variable&flag) generate a compile error, I write a funtion that does the same

integer And(integer iA,integer iB) {
    integer iTmp;
    for(iTmp=0;iTmp<32;iTmp+=1) {
        integer iBitA=iA%2;
        integer iBitB=iB%2;
        if(iBitA==iBitB) {
            if(iBitA!=0) return(TRUE);
        }
        iA/=2; // remove the bit for next check
        iB/=2; // remove the bit for next check
    }
    return(FALSE);
}

 

So now you can compare an bit level in your script meanwhile wait for the system is able to do.

 

I need to add some other events in bot script by the time.

 

 

 
New Post 5/5/2008 4:57 PM
User is offline Macca (Ret)
78 posts
Openlife Apprentice


Re: Testing script LS vs OG 

Thank you for the information.

I am sure that scripters, new and old, will find good uses with your help.


Working towards a red dot. It's all I have for now. [and no, I couldn't just leave]
 
Previous Previous
 
Next Next
  Openlife Forums  Scripting  LSL Discussion  Testing script LS vs OG
Privacy Statement | Terms Of UseAll Rights Reserved 2007,2008 3DX - Openlifegrid.com