Jump to content

Script optimisation question


arisaie
 Share

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

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

Recommended Posts

I am working on a script for my HUD, and finally figured out (I hope) how to use lists for storing data. Before that I was using a bunch of if statements [if (message == "" && string == "")] but that was using a lot of script memory (according to llGetUsedMemory()), so I thought..I cant use that.

Well, I was done with the 3 main HUD options (COLOR, GLOW, LENGTH, using around 30 000 bytes of script memory) and I figured out how to save the data so the options can be clicked interchargeably - showing and hiding faces (length), applying glow only on shown faces, hiding glow on hidden faces. But then I got to the 4th option (DISPLAY  - displaying and hiding a pair of 5 pairs total) and again I am going to run out of script memory if I continue.
 

I included  the integers and strings I am not using and the notes I have to keep track of some statements.

At first I wanted to use the llList2CSV for descriptions (Lengths- short , medium, long) list descS = ["1", "2", "3"] but integer iDescriptionS = llList2Integer(desclist,1) and index 2 were returning 0 so I kind of bypassed it with the lists and integers and strings (just below listen event) and it worked it seems.

I dont know why the llList2CSV works with the floats for the DISPLAY . 

As you can see in the COLOR (White and red only) section, I used the DISPLAY floats for alpha in PRIM_COLOR, to keep track of which pair is shown or hidden (Pairs LINK 2-3, 4-5,....10-11, LINK 1 is the ROOT PRIM). Without this, if I hid a pair and changed the color, it would become visible. But this additional 9 rows of PRIM_LINK_TARGET adds around 1 000B of memory per color (at least according to llGetUSedMemory()). I would have to add similar lines to keep track of which pair is shown or hidden to GLOW and LENGTH too (otherwise they all get shown when click in the HUD). 

Is there any way how to fix this, or am I worrying about nothing?

The only way I could bypass it, is to make do with it and just letting the user SHOW or HIDE the pair last after setting the previous options...

or making a button to delete the script after using the HUD and being satisfied with the settings(which I propably will do anyway)

I hope I am making sense and this question is not very demanding and the answer too complex for wonderful help that is provided here...I am learning as I go. If it's above the help provided here (justified) I guess I'll have to look for an experienced scripter. I just like to figure out things myself and learn.

I included the picture of my HUD layout.

settings.png

Edited by arisaie
Link to comment
Share on other sites

Added the code in reply as it was freezing my view. SOme integers are not used and llSetTimerEvent() is for color cycle settigngs which is not done yet

integer dChannel;
integer lHandle;
key id;
list pattern = [<1.0, 1.0, 1.0>, <1.0, 0.0, 0.498>, <0.929, 0.635, 0.337>];
float interval = 0.2;
integer color_index;
integer prim = LINK_SET;
integer face = ALL_SIDES;
list glow_index = [];

default
{
    
    changed(integer change)
    {
        if(change & (CHANGED_OWNER | CHANGED_INVENTORY))
        {
            llResetScript();
        }
    }
    
    state_entry()
    
    {
       dChannel = 1;
       id = llDetectedKey(0);
       lHandle = llListen(dChannel, "", "", "");
    }

    listen(integer channel, string size, key id, string message)
    
    {
        
        list descriptionS = ["1"]; 
        
        list descriptionM = ["2"];
         
        list descriptionL = ["3"];    
          
        string  stringDescriptionS = llList2String(descriptionS, 0); 
        integer iDescriptionS = llList2Integer(descriptionS, 0);
         
        string  stringDescriptionM = llList2String(descriptionM, 0); 
        integer iDescriptionM = llList2Integer(descriptionM, 0);
        
        string  stringDescriptionL = llList2String(descriptionL, 0);  
        integer iDescriptionL = llList2Integer(descriptionL, 0);
        
        list isLength1 = llGetLinkPrimitiveParams(4, [PRIM_DESC]);
        integer iIsLength1 = llList2Integer(isLength1, 0);
        
        list isLength2 = llGetLinkPrimitiveParams(6, [PRIM_DESC]);
        integer iIsLength2 = llList2Integer(isLength2, 0);
        
        list isLength3 = llGetLinkPrimitiveParams(8, [PRIM_DESC]);
        integer iIsLength3 = llList2Integer(isLength3, 0);
        
        list listLength = llGetLinkPrimitiveParams(1, [PRIM_DESC]);
        string listLen = llList2String(listLength, 0);

//BELOW IS THE DISPLAY
        
        list hidden = llGetLinkPrimitiveParams(3, [PRIM_DESC,
                                            PRIM_LINK_TARGET, 5, PRIM_DESC,
                                            PRIM_LINK_TARGET, 7, PRIM_DESC,
                                            PRIM_LINK_TARGET, 9, PRIM_DESC,
                                            PRIM_LINK_TARGET, 11, PRIM_DESC]);
        string CSV = llList2CSV(hidden);
        
        float SH23 = llList2Float(hidden, 0);
        float SH45 = llList2Float(hidden, 1);
        float SH67 = llList2Float(hidden, 2);
        float SH89 = llList2Float(hidden, 3);
        float SH1011 = llList2Float(hidden, 4);
                                            
       // integer integerHidden = llString2Integer(CSV, 0);
                                             
         // list descS = ["1", "2", "3"];
       // string descriptionShort = llList2CSV(descS)       ;
        
        // list descM= ["2", "1", "3"];
       // string descriptionMedium = llList2CSV(descM);
        
       // list descL= ["3", "1", "2"];
       // string iDescriptionMong = llList2CSV(descL);  
       // list desclist = llCSV2List(listLen); 
       // integer iDescriptionS = llList2Integer(desclist, 0);
       // integer iDescriptionM = llList2Integer(desclist, 1);
       // integer iDescriptionL = llList2Integer(desclist, 2);
       
//----------------------------END OF DISPLAY       
        list listGlow = llGetLinkPrimitiveParams(2, [PRIM_DESC]);
        float glow = llList2Float(listGlow, 0);

        vector color = llList2Vector(llGetLinkPrimitiveParams(1, [PRIM_COLOR, ALL_SIDES]), 0);
        
        
        if(message == "stat") llSay(0, (string)SH23 + " " +(string)SH45 + " " +(string)SH67 + " " + (string)SH1011);
                
//WHITE--------------------------------
        
        if (message == "KWColWhite")
        { 

            llSetLinkPrimitiveParamsFast(2, [PRIM_COLOR, iIsLength1, <1.0, 1.0, 1.0>, SH23, // MAIN FACE
                                PRIM_LINK_TARGET, 3, PRIM_COLOR, iIsLength1, <1.0, 1.0, 1.0>, SH23,
                                PRIM_LINK_TARGET, 4, PRIM_COLOR, iIsLength1, <1.0, 1.0, 1.0>, SH45,
                                PRIM_LINK_TARGET, 5, PRIM_COLOR, iIsLength1, <1.0, 1.0, 1.0>, SH45,
                                PRIM_LINK_TARGET, 6, PRIM_COLOR, iIsLength1, <1.0, 1.0, 1.0>, SH67,
                                PRIM_LINK_TARGET, 7, PRIM_COLOR, iIsLength1, <1.0, 1.0, 1.0>, SH67,
                                PRIM_LINK_TARGET, 8, PRIM_COLOR, iIsLength1, <1.0, 1.0, 1.0>, SH89,
                                PRIM_LINK_TARGET, 9, PRIM_COLOR, iIsLength1, <1.0, 1.0, 1.0>, SH89,
                                PRIM_LINK_TARGET, 10, PRIM_COLOR, iIsLength1, <1.0, 1.0, 1.0>, SH1011,
                                PRIM_LINK_TARGET, 11, PRIM_COLOR, iIsLength1, <1.0, 1.0, 1.0>, SH1011,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength2, <1.0, 1.0, 1.0>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength3, <1.0, 1.0, 1.0>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, 0, <1.0, 1.0, 1.0>, 0.0, //BASE COLOR
                                PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0, //BASE GLOW
                                PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>, 0.0,//ROOT COLOR
                                PRIM_LINK_TARGET, 1, PRIM_GLOW, 0, 0.0]); //ROOT GLOW
                                
                                
            llSetTimerEvent(0);
        }
        
        
            
//RED---------------------------------------------------------------------

        if (message == "KWColRed")
        {
     
            llSetLinkPrimitiveParamsFast(2, [PRIM_COLOR, iIsLength1, <1.0, 0.0, 0.498>, SH23, // MAIN FACE
                                PRIM_LINK_TARGET, 3, PRIM_COLOR, iIsLength1, <1.0, 0.0, 0.498>, SH23,
                                PRIM_LINK_TARGET, 4, PRIM_COLOR, iIsLength1, <1.0, 0.0, 0.498>, SH45,
                                PRIM_LINK_TARGET, 5, PRIM_COLOR, iIsLength1, <1.0, 0.0, 0.498>, SH45,
                                PRIM_LINK_TARGET, 6, PRIM_COLOR, iIsLength1, <1.0, 0.0, 0.498>, SH67,
                                PRIM_LINK_TARGET, 7, PRIM_COLOR, iIsLength1, <1.0, 0.0, 0.498>, SH67,
                                PRIM_LINK_TARGET, 8, PRIM_COLOR, iIsLength1, <1.0, 0.0, 0.498>, SH89,
                                PRIM_LINK_TARGET, 9, PRIM_COLOR, iIsLength1, <1.0, 0.0, 0.498>, SH89,
                                PRIM_LINK_TARGET, 10, PRIM_COLOR, iIsLength1, <1.0, 0.0, 0.498>, SH1011,
                                PRIM_LINK_TARGET, 11, PRIM_COLOR, iIsLength1, <1.0, 0.0, 0.498>, SH1011,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength2, <1.0, 0.0, 0.498>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength3, <1.0, 0.0, 0.498>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, 0, <1.0, 0.0, 0.498>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0, 
                                PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, <1.0, 0.0, 0.498>, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_GLOW, 0, 0.0]);
                                
            llSetTimerEvent(0);
            
        }

            
//ORANGE---------------------------------------------------------------------


        if (message == "KWColOrange")
        {
     
            llSetLinkPrimitiveParamsFast(LINK_SET,[ PRIM_COLOR, iIsLength1, <0.929, 0.635, 0.337>, 1.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength2, <0.929, 0.635, 0.337>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength3, <0.929, 0.635, 0.337>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, 0, <0.929, 0.635, 0.337>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, <0.929, 0.635, 0.337>, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_GLOW, 0, 0.0]);
                                
            llSetTimerEvent(0);
            
        } 
        
            
//YE3OW---------------------------------------------------------------------

        if (message == "KWColYellow")
        {
         
            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, iIsLength1, <0.929, 0.929, 0.388>, 1.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength2, <0.929, 0.929, 0.388>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength3, <0.929, 0.929, 0.388>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, 0, <0.929, 0.929, 0.388>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, <0.929, 0.929, 0.388>, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_GLOW, 0, 0.0]);
                                
            llSetTimerEvent(0);
            
        }
        
            
//Green---------------------------------------------------------------------

        if (message == "KWColGreen")
        {
     
            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, iIsLength1, <0.365, 1.000, 0.365>, 1.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength2, <0.365, 1.000, 0.365>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength3, <0.365, 1.000, 0.365>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, 0, <0.365, 1.000, 0.365>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, <0.365, 1.000, 0.365> , 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_GLOW, 0, 0.0]);
                                
            llSetTimerEvent(0);
        
        }
        

            
//Torqiose---------------------------------------------------------------------

        if (message == "KWColTorquise")
        {
     
            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, iIsLength1, <0.467, 0.929, 0.929>, 1.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength2, <0.467, 0.929, 0.929>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength3, <0.467, 0.929, 0.929>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, 0, <0.467, 0.929, 0.929>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, <0.467, 0.929, 0.929>, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_GLOW, 0, 0.0]);
                                
            llSetTimerEvent(0);
        
        }  
                   
            
//Blue---------------------------------------------------------------------

        if (message == "KWColBlue")
        {
     
            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, iIsLength1, <0.192, 0.596, 1.000>, 1.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength2, <0.192, 0.596, 1.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength3, <0.192, 0.596, 1.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, 0, <0.192, 0.596, 1.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, <0.192, 0.596, 1.000>, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_GLOW, 0, 0.0]);
                                
            llSetTimerEvent(0);
        
        }
            
            
//Purple---------------------------------------------------------------------

        if (message == "KWColPurple")
        {
         
            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, iIsLength1, <0.647, 0.294, 1.000>, 1.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength2, <0.647, 0.294, 1.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength3, <0.647, 0.294, 1.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, 0, <0.647, 0.294, 1.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, <0.647, 0.294, 1.000>, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_GLOW, 0, 0.0]);
                                
            llSetTimerEvent(0);
        
        }    
                            
            
//Pink---------------------------------------------------------------------

        if (message == "KWColPink")
        {
     
            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, iIsLength1, <0.996, 0.325, 1.000>, 1.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength2, <0.996, 0.325, 1.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength3, <0.996, 0.325, 1.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, 0, <0.996, 0.325, 1.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, <0.996, 0.325, 1.000>, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_GLOW, 0, 0.0]);
                                
            llSetTimerEvent(0);
        
        }    
          
            
//Black---------------------------------------------------------------------

        if (message == "KWColBlack")
        {
         
            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_COLOR, iIsLength1, <0.0, 0.0, 0.000>, 1.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength2, <0.0, 0.0, 0.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength3, <0.0, 0.0, 0.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, 0, <0.0, 0.0, 0.000>, 0.0,
                                PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, <0.0, 0.0, 0.000>, 0.0,
                                PRIM_LINK_TARGET, 1, PRIM_GLOW, 0, 0.0]);
                                
            llSetTimerEvent(0);
        
        }                  
        
//GLOW--------------------------------------------------------------------

        if (message == "KWGlow5")
        {

            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_GLOW, iIsLength1, 0.05, //ACTIVE FACE
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0, //BASE
                                         PRIM_LINK_TARGET, 1, PRIM_GLOW, ALL_SIDES, 0.00, //ORIGIN
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iIsLength2, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iIsLength3, 0.0,
                                         PRIM_LINK_TARGET, 2, PRIM_DESC, "0.05"]); //GLOW STRENGTH DESC
        }
        
         if (message == "KWGlow10")
        {

            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_GLOW, iIsLength1, 0.1,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0,
                                         PRIM_LINK_TARGET, 1, PRIM_GLOW, ALL_SIDES, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iIsLength2, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iIsLength3, 0.0,
                                         PRIM_LINK_TARGET, 2, PRIM_DESC, "0.1"]);
        }
        
        if (message == "KWGlow20")
        {

            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_GLOW, iIsLength1, 0.2,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0,
                                         PRIM_LINK_TARGET, 1, PRIM_GLOW, ALL_SIDES, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iIsLength2, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iIsLength3, 0.0,
                                         PRIM_LINK_TARGET, 2, PRIM_DESC, "0.2"]);

        }
        
        if (message == "KWGlow30")
        {

            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_GLOW, iIsLength1, 0.3,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0, 
                                         PRIM_LINK_TARGET, 1, PRIM_GLOW, ALL_SIDES, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iIsLength2, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iIsLength3, 0.0,
                                         PRIM_LINK_TARGET, 2, PRIM_DESC, "0.3"]);
        }
        
        if (message == "KWGlowOFF")
        {

            llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_GLOW, iIsLength1, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0,
                                         PRIM_LINK_TARGET, 1, PRIM_GLOW, ALL_SIDES, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iIsLength2, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iIsLength3, 0.0,
                                         PRIM_LINK_TARGET, 2, PRIM_DESC, "0.0"]); 

        }
        
        
        
//LENGTH--------------------------------------------------------------------- 
          
        if (message == "KWLenShort")
        {
             
            llSetLinkPrimitiveParamsFast(4, [PRIM_DESC, stringDescriptionS,
                                        PRIM_LINK_TARGET, 6, PRIM_DESC, stringDescriptionM,
                                        PRIM_LINK_TARGET, 8, PRIM_DESC, stringDescriptionL]);
            
            
            llSetLinkPrimitiveParams(LINK_SET, [PRIM_COLOR, 0, color, 0.0, //BASE
                                        PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iDescriptionS, color, 1.0,//SHOW
                                        PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iDescriptionM, color, 0.0,//HIDE
                                        PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iDescriptionL, color, 0.0,
                                        PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iDescriptionS, glow,//GLOW ACTIVE
                                        PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iDescriptionM, 0.0,
                                        PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iDescriptionL, 0.0,
                                        PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, color, 0.0,//ROOT COLOR
                                        PRIM_LINK_TARGET, 1, PRIM_GLOW, ALL_SIDES, 0.0]); //ROOT
            
        }
        

        
        //MEDIUM
        
        if (message == "KWLenMedium")
        {
            
             llSetLinkPrimitiveParamsFast(4, [PRIM_DESC, stringDescriptionM,
                                        PRIM_LINK_TARGET, 6, PRIM_DESC, stringDescriptionS,
                                        PRIM_LINK_TARGET, 8, PRIM_DESC, stringDescriptionL]);
            
            llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_COLOR, 0, color, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iDescriptionM, color, 1.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iDescriptionS, color, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iDescriptionL, color, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iDescriptionM, glow,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iDescriptionS, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iDescriptionL, 0.0,
                                         PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, color, 0.0,
                                         PRIM_LINK_TARGET, 1, PRIM_GLOW, ALL_SIDES, 0.0]);
            
        }
        

        
        //LONG
        if (message == "KWLenLong")
        {
            
            llSetLinkPrimitiveParamsFast(4, [PRIM_DESC, stringDescriptionL,
                                        PRIM_LINK_TARGET, 6, PRIM_DESC, stringDescriptionS,
                                        PRIM_LINK_TARGET, 8, PRIM_DESC, stringDescriptionM]);
            
            llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_COLOR, 0, color, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iDescriptionL, color, 1.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iDescriptionS, color, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iDescriptionM, color, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iDescriptionL, glow,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iDescriptionS, 0.0,
                                         PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, iDescriptionM, 0.0,
                                         PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, color, 0.0,
                                         PRIM_LINK_TARGET, 1, PRIM_GLOW, ALL_SIDES, 0.0]);
        }
             
//DISPLAY-------------------------------------------------------------------------      

list isHidden = ["0.0"];
list isShown = ["1.0"];

string sHidden = llList2String(isHidden, 0);
string sShown = llList2String(isShown, 0);
        
    if (message == "KWDisplayHide1")
    
    {

  llSetLinkPrimitiveParamsFast(2, [PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, 2, PRIM_GLOW, iIsLength1, 0.0,
                                   PRIM_LINK_TARGET, 3, PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, 3, PRIM_GLOW, iIsLength1, 0.0,
                                   PRIM_LINK_TARGET, 3, PRIM_DESC, sHidden]);
                                    
                                    
  
  
    }
    
     if (message == "KWDisplayShow1")
    
    {

  llSetLinkPrimitiveParamsFast(2, [PRIM_COLOR, iIsLength1, color, 1.0,
                                    PRIM_LINK_TARGET, 2, PRIM_GLOW, iIsLength1, glow ,
                                    PRIM_LINK_TARGET, 3, PRIM_COLOR, iIsLength1, color, 1.0,
                                    PRIM_LINK_TARGET, 3, PRIM_GLOW, iIsLength1, glow,
                                    PRIM_LINK_TARGET, 3, PRIM_DESC, sShown]);
  
    } 
    
    if (message == "KWDisplayHide2")
    
    {

  llSetLinkPrimitiveParamsFast(4, [PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, 4, PRIM_GLOW, iIsLength1, 0.0,
                                   PRIM_LINK_TARGET, 5, PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, 5, PRIM_GLOW, iIsLength1, 0.0,
                                   PRIM_LINK_TARGET, 5, PRIM_DESC, sHidden]);
                            
  
    }
    
    if (message == "KWDisplayShow2")
    
    {

  llSetLinkPrimitiveParamsFast(4, [PRIM_COLOR, iIsLength1, color, 1.0,
                                    PRIM_LINK_TARGET, 4, PRIM_GLOW, iIsLength1, glow ,
                                    PRIM_LINK_TARGET, 5, PRIM_COLOR, iIsLength1, color, 1.0,
                                    PRIM_LINK_TARGET, 5, PRIM_GLOW, iIsLength1, glow,
                                    PRIM_LINK_TARGET, 5, PRIM_DESC, sShown]);
  
    } 
    
    if (message == "KWDisplayHide3")
    
    {

  llSetLinkPrimitiveParamsFast(6, [PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, 6, PRIM_GLOW, iIsLength1, 0.0,
                                   PRIM_LINK_TARGET, 7, PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, 7, PRIM_GLOW, iIsLength1, 0.0,
                                   PRIM_LINK_TARGET, 7, PRIM_DESC, sHidden]);
                            
  
    }
    
    if (message == "KWDisplayShow3")
    
    {

  llSetLinkPrimitiveParamsFast(6, [PRIM_COLOR, iIsLength1, color, 1.0,
                                    PRIM_LINK_TARGET, 6, PRIM_GLOW, iIsLength1, glow ,
                                    PRIM_LINK_TARGET, 7, PRIM_COLOR, iIsLength1, color, 1.0,
                                    PRIM_LINK_TARGET, 7, PRIM_GLOW, iIsLength1, glow,
                                    PRIM_LINK_TARGET, 7, PRIM_DESC, sShown]);
  
    }
    
    if (message == "KWDisplayHide4")
    
    {

  llSetLinkPrimitiveParamsFast(8, [PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, 8, PRIM_GLOW, iIsLength1, 0.0,
                                   PRIM_LINK_TARGET, 9, PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, 9, PRIM_GLOW, iIsLength1, 0.0,
                                   PRIM_LINK_TARGET, 9, PRIM_DESC, sHidden]);
                            
  
    }
    
    if (message == "KWDisplayShow4")
    
    {

  llSetLinkPrimitiveParamsFast(8, [PRIM_COLOR, iIsLength1, color, 1.0,
                                    PRIM_LINK_TARGET, 8, PRIM_GLOW, iIsLength1, glow ,
                                    PRIM_LINK_TARGET, 9, PRIM_COLOR, iIsLength1, color, 1.0,
                                    PRIM_LINK_TARGET, 9, PRIM_GLOW, iIsLength1, glow,
                                    PRIM_LINK_TARGET, 9, PRIM_DESC, sShown]);
  
    }  
    
    if (message == "KWDisplayHide5")
    
    {

  llSetLinkPrimitiveParamsFast(10, [PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, 10, PRIM_GLOW, iIsLength1, 0.0,
                                   PRIM_LINK_TARGET, 11, PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, 11, PRIM_GLOW, iIsLength1, 0.0,
                                   PRIM_LINK_TARGET, 11, PRIM_DESC, sHidden]);
                            
  
    }
    
    if (message == "KWDisplayShow5")
    
    {

  llSetLinkPrimitiveParamsFast(10, [PRIM_COLOR, iIsLength1, color, 1.0,
                                    PRIM_LINK_TARGET, 10, PRIM_GLOW, iIsLength1, glow ,
                                    PRIM_LINK_TARGET, 11, PRIM_COLOR, iIsLength1, color, 1.0,
                                    PRIM_LINK_TARGET, 11, PRIM_GLOW, iIsLength1, glow,
                                    PRIM_LINK_TARGET, 11, PRIM_DESC, sShown]);
  
    } 


        
//-------------------------------------------------------------------------        
        if (message == "mem")
        {
            integer used_memory = llGetUsedMemory();
            integer free_memory = llGetFreeMemory();
llOwnerSay((string)used_memory + " bytes of memory currently used." + (string)free_memory + " free memory");
}
   }     
        


}

 

Edited by arisaie
Link to comment
Share on other sites

Hoo boy, lots of things to discuss here.

First things first:

  • Why do you create so many variables? Each variable consume valuable heap space
  • Combine similar literal lists into one, varying only as needed through a variable or through list concatenation/appending
  • Assign directly to variables using typecasts, don't go through a list.
  • Use return results directly inside a function call if possible.

For example:

list descriptionS = ["1"];
string  stringDescriptionS = llList2String(descriptionS, 0);
integer iDescriptionS = llList2Integer(descriptionS, 0);

Why? Do direct assignment like this:

string  stringDescriptionS = "1";
integer iDescriptionS = (integer)stringDescriptionS;

If one form is used many times while the other is used only once or twice, consider storing onlly the type commonly used, and use typecasting when a different type is needed.

Next the multiple lists that all differ on the color value. Why do you have to create several literal lists like that?

Based on selection, you assign a value to a variable, and build the literal list only once:

//WHITE--------------------------------

        if (message == "KWColWhite")
        {
            vector KWCol = <1.0, 1.0, 1.0>;
        }

//RED---------------------------------------------------------------------

        if (message == "KWColRed")
        {
            vector KWCol = <1.0, 0.0, 0.498>;
        }

// --- many snipped ---

        if (llGetSubString(message, 0, 4) == "KWCol")
        {
            llSetLinkPrimitiveParamsFast(2, [PRIM_COLOR, iIsLength1, KWCol, SH23, // MAIN FACE
                            PRIM_LINK_TARGET, 3, PRIM_COLOR, iIsLength1, KWCol, SH23,
                            PRIM_LINK_TARGET, 4, PRIM_COLOR, iIsLength1, KWCol, SH45,
                            PRIM_LINK_TARGET, 5, PRIM_COLOR, iIsLength1, KWCol, SH45,
                            PRIM_LINK_TARGET, 6, PRIM_COLOR, iIsLength1, KWCol, SH67,
                            PRIM_LINK_TARGET, 7, PRIM_COLOR, iIsLength1, KWCol, SH67,
                            PRIM_LINK_TARGET, 8, PRIM_COLOR, iIsLength1, KWCol, SH89,
                            PRIM_LINK_TARGET, 9, PRIM_COLOR, iIsLength1, KWCol, SH89,
                            PRIM_LINK_TARGET, 10, PRIM_COLOR, iIsLength1, KWCol, SH1011,
                            PRIM_LINK_TARGET, 11, PRIM_COLOR, iIsLength1, KWCol, SH1011,
                            PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength2, KWCol, 0.0,
                            PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, iIsLength3, KWCol, 0.0,
                            PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, 0, KWCol, 0.0, //BASE COLOR
                            PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, 0, 0.0, //BASE GLOW
                            PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, KWCol, 0.0,//ROOT COLOR
                            PRIM_LINK_TARGET, 1, PRIM_GLOW, 0, 0.0]); //ROOT GLOW
            llSetTimerEvent(0);
        }

Every literal list you define in the code, consumes space. You created lots of literal lists.

Similarly for the branches handling "KWDisplayShowN"/"KWDisplayHideN": Roll them into one like this:

if (llGetSubString(message, 0, 8) == "KWDisplay") {
    integer which = (integer)llGetSubString(message, -1, -1);
    integer link1;
    integer link2;
    float link_glow;
    string link_desc;
    if (llGetSubString(message, 9, 12) == "Hide")
    {
        link_glow = 0.0;
        link_desc = sHidden;
    }
    else
    {
        // "Show"
        link_glow = glow;
        link_desc = sShown;
    }
    if (which == 1) {
        link1 = 2;
        link2 = 3;
    }
    if (which == 2) {
        link1 = 4;
        link2 = 5;
    }
    //
    // -- and so on until which == 5 --
    //
    llSetLinkPrimitiveParamsFast(2, [PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, link1, PRIM_GLOW, iIsLength1, link_glow,
                                   PRIM_LINK_TARGET, link2, PRIM_COLOR, iIsLength1, color, 0.0,
                                   PRIM_LINK_TARGET, link2, PRIM_GLOW, iIsLength1, link_glow,
                                   PRIM_LINK_TARGET, link2, PRIM_DESC, link_desc]);
}

Again, you end up with just one literal list. Saving a LOT of memory compared to previously when you created 10 (ten!) literal lists.

For the "KWLen" part, you can also do the same:

if (llGetSubString(message, 0, 4) == "KWLen") {
    string lenword = llGetSubString(message, 5, -1);
    string desc1;
    string desc2;
    string desc3;
    if (lenword == "Short") {
        desc1 = stringDescriptionS;
        desc2 = stringDescriptionM;
        desc3 = stringDescriptionL;
    }
    if (lenword == "Medium") {
        desc1 = stringDescriptionM;
        desc2 = stringDescriptionS;
        desc3 = stringDescriptionL;
    }
    if (lenword == "Long") {
        desc1 = stringDescriptionL;
        desc2 = stringDescriptionS;
        desc3 = stringDescriptionM;
    }
    llSetLinkPrimitiveParamsFast(4, [PRIM_DESC, desc1,
                                PRIM_LINK_TARGET, 6, PRIM_DESC, desc2,
                                PRIM_LINK_TARGET, 8, PRIM_DESC, desc3]);
    
    llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_COLOR, 0, color, 0.0,
                                 PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, desc1, color, 1.0,
                                 PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, desc2, color, 0.0,
                                 PRIM_LINK_TARGET, LINK_SET, PRIM_COLOR, desc2, color, 0.0,
                                 PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, desc1, glow,
                                 PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, desc2, 0.0,
                                 PRIM_LINK_TARGET, LINK_SET, PRIM_GLOW, desc3, 0.0,
                                 PRIM_LINK_TARGET, 1, PRIM_COLOR, ALL_SIDES, color, 0.0,
                                 PRIM_LINK_TARGET, 1, PRIM_GLOW, ALL_SIDES, 0.0]);
}

Again, just 2 literal lists, where before you created 6 literal lists.

I'm sure there are other optimizations, but start from here. As I see it, the literal lists are the things that consume a lot of your script memory.

 

  • Thanks 1
Link to comment
Share on other sites

You have a lot of extraneous PRIM_LINK_TARGET's in there that you could probably cull. Whenever you specify a link target, all params that follow will continue to target that same preceding PRIM_LINK_TARGET until a new one is specified.

For example, this:

llSetLinkPrimitiveParamsFast(2, [PRIM_COLOR, iIsLength1, color, 0.0,
                                 PRIM_LINK_TARGET, 2, PRIM_GLOW, iIsLength1, 0.0,
                                 PRIM_LINK_TARGET, 3, PRIM_COLOR, iIsLength1, color, 0.0,
                                 PRIM_LINK_TARGET, 3, PRIM_GLOW, iIsLength1, 0.0,
                                 PRIM_LINK_TARGET, 3, PRIM_DESC, sHidden]);

Can be written as this: (indentation added for clarity)

llSetLinkPrimitiveParamsFast(2, [        //initially targeting link 2
    PRIM_COLOR, iIsLength1, color, 0.0,  //link 2
    PRIM_GLOW, iIsLength1, 0.0,          //link 2
  PRIM_LINK_TARGET, 3,                   //now targeting link 3
    PRIM_COLOR, iIsLength1, color, 0.0,  //link 3
    PRIM_GLOW, iIsLength1, 0.0,          //link 3
    PRIM_DESC, sHidden                   //link 3
]);

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

A small note about the short/medium/long options, AKA stringDescriptionS/iDescriptionS:

Since stringDescriptionS seems to be intended as a link number, the code can be changed to make more sense semantically.

  1. Remove stringDescriptionS/M/L completely. Keep iDescriptionS (and maybe rename it to something more specific like iShortLinknum).
  2. While setting PRIM_DESC, use (string)iDescriptionS (or (string)iShortLinknum) as the value. This is a more meaningful way to do what you intend.

 

17 hours ago, arisaie said:

At first I wanted to use the llList2CSV for descriptions (Lengths- short , medium, long) list descS = ["1", "2", "3"] but integer iDescriptionS = llList2Integer(desclist,1) and index 2 were returning 0 so I kind of bypassed it

Do I understand correctly that you used llList2CSV(descS) for PRIM_DESC, and later got the description from a link, then tried to use llList2Integer before you separated with llCSV2List?

Edited by Wulfie Reanimator
Link to comment
Share on other sites

On 1/25/2023 at 4:26 AM, primerib1 said:

Hoo boy, lots of things to discuss here.

First things first:

  • Why do you create so many variables? Each variable consume valuable heap space
  • Combine similar literal lists into one, varying only as needed through a variable or through list concatenation/appending
  • Assign directly to variables using typecasts, don't go through a list.
  • Use return results directly inside a function call if possible.

 

Thank you primerib! It took me a while but managed to make it work.

Without your examples I dont think I would be able to figure it out. I certainly learned new things. I did the GLOW the same way and all selections can be selected interchargeably. Even the script memory dropped by 10 000 bytes.

Thanks a lot!

On 1/25/2023 at 5:25 PM, Wulfie Reanimator said:

A small note about the short/medium/long options, AKA stringDescriptionS/iDescriptionS:

Since stringDescriptionS seems to be intended as a link number, the code can be changed to make more sense semantically.

  1. Remove stringDescriptionS/M/L completely. Keep iDescriptionS (and maybe rename it to something more specific like iShortLinknum).
  2. While setting PRIM_DESC, use (string)iDescriptionS (or (string)iShortLinknum) as the value. This is a more meaningful way to do what you intend.

 

Do I understand correctly that you used llList2CSV(descS) for PRIM_DESC, and later got the description from a link, then tried to use llList2Integer before you separated with llCSV2List?

Thanks wulfie.

If only I remembered about the llList2CSV! I removed it and have not used it again.

  • Like 1
Link to comment
Share on other sites

On 1/27/2023 at 5:10 AM, arisaie said:

Thank you primerib! It took me a while but managed to make it work.

Without your examples I dont think I would be able to figure it out. I certainly learned new things. I did the GLOW the same way and all selections can be selected interchargeably. Even the script memory dropped by 10 000 bytes.

Thanks a lot!

Glad to help!

I'll be happy to suggest other optimizations, though likely not as massive as the list consolidation tip I gave.

Lists are the worst offenders in term of memory usage. Try to keep them in the stack where they will be cleaned up before every function call; keeping them in heap space means you're dependent on when the Garbage Collector gets triggered, and before the GC does its magic, you may still run out of space in heap.

As a rule of thumb, everything on the right side of an assignment operator, and/or everything within the parameter list of a function call, are kept in stack. The assignment operator copies the result of the right side into the heap.

(Some have suggested calling llSleep(0.01); to trigger GC. It _will_ add a (very slight) pause to your script, but might be worth it to be called at strategic places.)

  • Like 2
Link to comment
Share on other sites

On 1/29/2023 at 8:00 AM, primerib1 said:

Glad to help!

I'll be happy to suggest other optimizations, though likely not as massive as the list consolidation tip I gave.

Lists are the worst offenders in term of memory usage. Try to keep them in the stack where they will be cleaned up before every function call; keeping them in heap space means you're dependent on when the Garbage Collector gets triggered, and before the GC does its magic, you may still run out of space in heap.

As a rule of thumb, everything on the right side of an assignment operator, and/or everything within the parameter list of a function call, are kept in stack. The assignment operator copies the result of the right side into the heap.

(Some have suggested calling llSleep(0.01); to trigger GC. It _will_ add a (very slight) pause to your script, but might be worth it to be called at strategic places.)

Never heard of the term garbage collector!

Thanks, I was wondering and meant to ask what exactly adds to the memory and increases it.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 451 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...