Reply
Rolig Loon
Posts: 24,642
Registered: ‎10-05-2009
0 Kudos

Preloading Slide Viewer

This basic preloading slide viewer was introduced by Sendao Goodman in 2007 and was in the LSL wiki's Scripting Library until sometime in 2011.  I have encountered several versions of it across Second Life, and have modified it myself many times for specific purposes. 

The operating principle of the unit is simple. Each slide in the unit's Contents is shown in turn on one of five faces of the root prim, all of which are colored black so that the slides are not visible.  By the time a slide is finally moved onto the one white face of the prim, it has been "preloaded" for all nearby avatars, so it rezzes instantly. 

This version is designed for a three-prim display unit.  It defaults to auto-advance mode with a cycle of 10 seconds, but the owner can change the speed or turn it off with a simple dialog menu. Anyone can also move to the next slide (or the previous one) manually by clicking on the viewer's "forward" or "reverse" button.

 

// PRE-LOAD and VIEW SLIDES
// Script by Sendao Goodman, 2007
// Modified by Rolig Loon 2009, 2010, 2011, 2012

//--------------------------

// Installation note: This is to be used in a linked 3-prim object.  
//      By default, slides show on face 2 of the root prim (the screen). 
//      One child prim, which must be named "forward", is the forward button. 
//      The other one, which must be named "reverse", is the reverse button. 

//--------------------------
// Drop this script and any images into the root prim and it will cycle every 10 seconds

// Owner: Touch the root prim (viewer screen) to change slide speed or turn it off.
// All Users: Touch the "forward" or "reverse" prim to change slides manually

float gPace = 10.0; 
integer gReload;
list gPics;
integer gLen;
integer gSlide;
integer gChan;
integer gLsn;

loadPictures()
{
    gPics=[];
    integer i = llGetInventoryNumber(INVENTORY_TEXTURE);
    if( i > 0 ) 
    {
        while( i > 0 ) 
        {
            i--;
            gPics += [llGetInventoryName(INVENTORY_TEXTURE,i)];
        }
        gLen = (gPics !=[]);
        llOwnerSay((string)gLen+" pictures loaded");
        gPics = llListSort( gPics, 1, TRUE ); // put them in order
        llOwnerSay("Slides are now set to advance every "+ (string)gPace + " seconds.");
        llSetTimerEvent(gPace);
    }
    else if( gReload == 0 ) 
    {
        llSetTimerEvent(0.0);
    }
}

string getSlide(integer slide)
{
    return llList2String( gPics, (slide+gLen)%gLen );
}

default
{
    on_rez(integer sp)
    {
        loadPictures();
        gSlide=0;
        gReload=0;
    }
    
    state_entry()
    {
        gChan = (integer)("0xF" + llGetSubString(llGetKey(),0,6));
        loadPictures();
        gSlide=0;
        gReload=0;
        llSetLinkColor(LINK_THIS, <0,0,0>, ALL_SIDES );
        llSetLinkColor(LINK_THIS, <1,1,1>, 2 ); // Slides displayed on this face are visible.  All other faces are colored black
    }
    
    listen(integer channel, string name, key id, string msg)
    {
        llListenRemove(gLsn);
        if(msg == "OFF")
        {
            gPace = 0.0;
        }
        else
        {
            gPace += (float)msg;
            if (gPace <= 0.0)
            {
                gPace = 0.0;
            }
        }
        llSetTimerEvent(gPace);
        llOwnerSay("Slides are now set to advance every "+ (string)gPace + " seconds.");
    }
    
    changed( integer ch )
    {
        if( ch & CHANGED_INVENTORY ) 
        {
            gReload = 1;
            llSetTimerEvent(2.0);
        }
    }

    touch_start(integer num)
    {
        if (llDetectedLinkNumber(0) == 1) // The root prim (viewer screen)
        {
            if (llDetectedKey(0) == llGetOwner()) 
            {
                gLsn = llListen(gChan,"","","");
                llDialog(llGetOwner()," \n\nSlides now advance every "+(string)gPace+ " seconds. Select a new speed.",["+2","+5","OFF","-2","-5"],gChan);
            }
        }    
        else if (llGetLinkName(llDetectedLinkNumber(0)) == "forward") //The forward button
        {
            if( gLen > 0 ) 
            {
                integer i=6;
                while( i > 0 ) 
                {
                    i--;
                    llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEXTURE,i,getSlide(gSlide+(i-2)),<1.0,1.0,0.0>,ZERO_VECTOR,0.0]);
                }
                gSlide = (gSlide+1)%gLen;
            }
        }
        else if (llGetLinkName(llDetectedLinkNumber(0)) == "reverse")  // The reverse button
        {
            if( gLen > 0 ) 
            {
                integer i=6;
                while( i > 0 ) 
                {
                    i--;
                    llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEXTURE,i,getSlide(gSlide+(i-3)),<1.0,1.0,0.0>,ZERO_VECTOR,0.0]);
                }
                gSlide = (gSlide-1)%gLen;
            }
        }
    }
    
    timer()
    {
        if( gReload == 1 ) 
        {
            gReload = 0;
            loadPictures();
            llSetTimerEvent(gPace);
        }
        else
        {
            integer i=6;
            while( i > 0 ) 
            {
                i--;
                llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEXTURE,i,getSlide(gSlide+(i-2)),<1.0,1.0,0.0>,ZERO_VECTOR,0.0]);
            }
            gSlide = (gSlide+1)%gLen;
        }
    }
}

 

Not as dumb as I look
Emma Krokus
Posts: 381
Registered: ‎01-17-2010
0 Kudos

Re: Preloading Slide Viewer

Reply to Rolig Loon - view message

Thank you Rolig - it's perfect :smileyhappy:

Emma :smileyhappy:

Resident
Sendao Goodman
Posts: 1
0 Kudos

Re: Preloading Slide Viewer

Reply to Rolig Loon - view message

That's awesome :smileyhappy: Thanks Rolig!