Jump to content

frozen list


RilaVirum
 Share

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

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

Recommended Posts

Need help please! I'm making a picture gallery and

I'm trying to make a texture cycle for it. My list isn't moving though! How do I get my list to move?  My script it keeps stopping at the 

list FRAMES = [ ];

integer FRONT = 0;

default
{
    state_entry()
    {
        //What COLOR for the SIDES?
        vector WHITE = <0.941, 0.941, 0.941>;
        vector BLACK = <0.148, 0.148, 0.148>;
        integer BACK = 5;
        integer LEFT = 3;
        integer RIGHT = 1;
        integer TOP = 2;
        integer BOTTOM = 4;

         list SIDES = [];
         { 
                SIDES += [PRIM_COLOR, FRONT, BLACK, 1.0];
                SIDES += [PRIM_COLOR, LEFT, WHITE, 1.0];
                SIDES += [PRIM_COLOR, RIGHT, WHITE, 1.0];
                SIDES += [PRIM_COLOR, TOP, WHITE, 1.0];
                SIDES += [PRIM_COLOR, BOTTOM, WHITE, 1.0];
                SIDES += [PRIM_COLOR, BACK, WHITE, 1.0];
                
          }
                llSetPrimitiveParams(SIDES);
    }
                
    touch_start(integer total_number)
    {
        state Carousel;
    }
}
    
state  Carousel 
{
    state_entry()
    {
        
        key Avatar = llDetectedKey(0);
        key click =  llDetectedKey(0);
        
        // PICTURE FRAMES Cycling through pictures M1 to M7
        integer Counter = 0;
        integer M1 = 0;
        integer M2 = 1;
        integer M3 = 2;
        integer M4 = 3;
        integer M5 = 4;
        integer M6 = 5;
        integer M7 = 6;
        integer Index = llGetInventoryNumber(INVENTORY_TEXTURE);
        llSetPrimitiveParams([PRIM_TEXTURE, 0, FRAMES, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
        
        if(Index == 0)
        
        return;
       
        
        if(Counter > Index - 1)
        
        Counter = 0;
         ++Counter;
       
     }
       
        list FRAMES = [];
        integer i;
        integer max = llGetListLength(FRAMES);
        for (i=0;i<max;i++)
        {
           
            
            FRAMES += [PRIM_TEXTURE, FRONT, M1];
            FRAMES += [PRIM_TEXTURE, FRONT, M2];
            FRAMES += [PRIM_TEXTURE, FRONT, M3];
            FRAMES += [PRIM_TEXTURE, FRONT, M4];
            FRAMES += [PRIM_TEXTURE, FRONT, M5];
            FRAMES += [PRIM_TEXTURE, FRONT, M6];
            FRAMES += [PRIM_TEXTURE, FRONT, M7];
        }          
       
        llSetPrimitiveParams(FRAMES);
       
    }
    
       if(click == Avatar)
        {
          llSay(0, "Click Me");
        }
    }
}
 

Link to comment
Share on other sites

Oh... I dunno. Here:

// list FRAMES = [ ];   
// Only going to show one "frame" at a time, so don't clutter up the script with a list
// that merely stores the UUIDs of what's in the object's Inventory.
// Instead just index directly on the inventory texture number

integer max;    // count of inventory textures
integer click;  // the current texture number, advanced by touch_start event
integer FRONT = 0;
// Maybe FRONT is global to be the face that gets the texture change?
// (Not sure why it's the one that gets painted BLACK, though)

default
{
    state_entry()
    {
        //What COLOR for the SIDES?
        vector WHITE = <0.941, 0.941, 0.941>;
        vector BLACK = <0.148, 0.148, 0.148>;
        integer BACK = 5;
        integer LEFT = 3;
        integer RIGHT = 1;
        integer TOP = 2;
        integer BOTTOM = 4;

         list SIDES = [];
         {  // don't need this set of curly braces, but they won't hurt anything
                SIDES += [PRIM_COLOR, FRONT, BLACK, 1.0];
                SIDES += [PRIM_COLOR, LEFT, WHITE, 1.0];
                SIDES += [PRIM_COLOR, RIGHT, WHITE, 1.0];
                SIDES += [PRIM_COLOR, TOP, WHITE, 1.0];
                SIDES += [PRIM_COLOR, BOTTOM, WHITE, 1.0];
                SIDES += [PRIM_COLOR, BACK, WHITE, 1.0];
                
          }
                llSetPrimitiveParams(SIDES);
        // inventory won't change with every click so count the textures here:
        max = llGetInventoryNumber(INVENTORY_TEXTURE);
    }
    touch_start(integer total_number)
    {
        // state Carousel;  
        // Let's avoid unnecessary state transitions whenever possible; just do the work here
        if (0 == max)
            return; // no textures in inventory (maybe give a warning?)
        string textureName = llGetInventoryName(INVENTORY_TEXTURE, click);
        llSetPrimitiveParams([PRIM_TEXTURE, FRONT, textureName, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
        click = (click + 1) % max;  // increment through textures each touch, modulo the count in inventory
    }
    changed(integer change)
    {
        if (CHANGED_INVENTORY & change)
            llResetScript();    // in case somebody added or removed textures
    }
}

I tried to find some way to use the original script as an instructional example but there's not much I could salvage, so this has little pedagogical value. Sorry.

In passing, it would be okay to pre-populate a list of all the texture names, which is what I guess FRAMES was intended to be, but that list adds code and memory to the script, and llGetInventoryName() to get the next texture is trivially cheap to call with each touch because we just don't click that fast.

Edited by Qie Niangao
  • Like 1
Link to comment
Share on other sites

@RilaVirum Ok, I think I see why your script is stopping at the assignment of an empty list to Frames. Assuming it's in the carousel state where this happens, the little block of code starting with the clearout of the list is not inside any particular state, and the following blocks aren't either.. You need to put them in functions and then call then from events within the Carousel state, such as a touch_end event.

I suspect that on state_entry to Carousel you would first initialise the faces, but then the detection of a click, the incrementing of counter, and the redisplay of the new face all need to be inside a touch event.

I think as well you should declare Sides and Frames as globals, at the moment sides is a local list that is only accessible to the state_entry event in the default state.

Edited by Profaitchikenz Haiku
Link to comment
Share on other sites

Ok, so when you said your script was "stopping" my assumptions that is was a compile error were correct. The difference between a script failing to compile and a script which is running then stopping with an error are important ones to understand. The revised script below compiles, but I haven't put any textures in so I have no idea of it will actually run or stop with an error.

A bit of fiddling in a sandbox has got a revised script that now compiles, but needs to be in a prim with a few textures. I have removed the second state as it isn't necessary in a simple application such as this.

The script has been changed to show you where global variables should go, where to factor out code into functions that may be called several times or only once but would otherwise clutter up the state or event code, and how to detect and use touch events.

To get it to work you will need to work out the UUID of a default or blank texture to be applied to all sides and insert that into clearFrames.

 

// revised script to show where global variables should go and
// how to factor out code into functions

list FRAMES = [];

integer FRONT = 0;

integer counter = -1;   // trick to increment it to 0 to acces the first texture

integer Index;

//What COLOR for the SIDES?
vector WHITE = <0.941, 0.941, 0.941>;
vector BLACK = <0.148, 0.148, 0.148>;
integer BACK = 5;
integer LEFT = 3;
integer RIGHT = 1;
integer TOP = 2;
integer BOTTOM = 4;

list SIDES = [];

integer M1 = 0;
integer M2 = 1;
integer M3 = 2;
integer M4 = 3;
integer M5 = 4;
integer M6 = 5;
integer M7 = 6;


clearFrames()
{
    FRAMES = [];
    // you need a texture uuid here such as blank or default to apply to the faces
    key blankTex = NULL_KEY; // but change it to be an actual texture
        //integer i;
        //integer max = llGetListLength(FRAMES);
        // the usde of a loop here will overfill the list, it just needs a simple sequence
        //for (i=0;i<max;i++)
        //{
           
         // must specify the texture UUID or string, and the repeats, offsets and rotation   
    FRAMES += [PRIM_TEXTURE, M1, blankTex, ZERO_VECTOR, ZERO_VECTOR, 0.0];
    FRAMES += [PRIM_TEXTURE, M2, blankTex, ZERO_VECTOR, ZERO_VECTOR, 0.0];
    FRAMES += [PRIM_TEXTURE, M3, blankTex, ZERO_VECTOR, ZERO_VECTOR, 0.0];
    FRAMES += [PRIM_TEXTURE, M4, blankTex, ZERO_VECTOR, ZERO_VECTOR, 0.0];
    FRAMES += [PRIM_TEXTURE, M5, blankTex, ZERO_VECTOR, ZERO_VECTOR, 0.0];
    FRAMES += [PRIM_TEXTURE, M6, blankTex, ZERO_VECTOR, ZERO_VECTOR, 0.0];
    FRAMES += [PRIM_TEXTURE, M7, blankTex, ZERO_VECTOR, ZERO_VECTOR, 0.0];
        //}          
       
    llSetPrimitiveParams(FRAMES);    
}

setSides()
{
    SIDES = [];
    SIDES += [PRIM_COLOR, FRONT, BLACK,1.0];
    SIDES += [PRIM_COLOR, LEFT, WHITE, 1.0];
    SIDES += [PRIM_COLOR, RIGHT, WHITE, 1.0];
    SIDES += [PRIM_COLOR, TOP, WHITE, 1.0];
    SIDES += [PRIM_COLOR, BOTTOM, WHITE, 1.0];
    SIDES += [PRIM_COLOR, BACK, WHITE, 1.0];
                
    llSetPrimitiveParams(SIDES);    
}

default
{
    state_entry()
    {
        clearFrames();
        setSides();

        Index = llGetInventoryNumber(INVENTORY_TEXTURE);
        llSetPrimitiveParams([PRIM_TEXTURE, 0, FRAMES, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
    }
                
    touch_start(integer total_number)
    {
        //state Carousel; redundant, it can all happen nicely in a single state
        key Avatar = llDetectedKey(0); // these are only valid in a click
        //key click =  llDetectedKey(0);

        //if(click == Avatar) will always be true so commented out
        //{
         // llSay(0, "Click Me");
        //}
        
        if( Index > 0) // don't do anything if there are no pictures
        {
            counter += 1;
            if( counter >= Index) counter = 0;
            // now get the texture name accessed by counter
            string thisTex = llGetInventoryName(INVENTORY_TEXTURE, counter);
            // and now apply thisTex to whatever face you are using as your display
            // 
  		llSetPrimitiveParams([PRIM_TEXTURE, FRONT, thisTex, ZERO_VECTOR, ZERO_VECTOR, 0.0]);
        }
        else
        {
            llWhisper(0, "There are no textures to display");
        }
    }
}

 

Edited by Profaitchikenz Haiku
  • Thanks 1
Link to comment
Share on other sites

You will need to make one rather important change to the PRIM_TEXTURE calls, the first of the two vectors should be <1.0, 1.0, 0.0> instead of ZERO_VECTOR. Since I wasn't throwing any textures at the test prim I never actually noticed it, the sides changed colour because the colours work regardless of the texture repeats.

  • Thanks 1
Link to comment
Share on other sites

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