Jump to content

Slideshow with preload option script


Sunbleached
 Share

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

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

Recommended Posts

Hello! I am trying to create a simple slideshow script with preload option based on this awesome example kindly given by Mollymews.

integer index;

integer number = llGetInventoryNumber(INVENTORY_TEXTURE);

if (number) 
{
   string name = llGetInventoryName(INVENTORY_TEXTURE, index);
   if (name != "") llSetTexture(name, ALL_SIDES);
   index = (++index) % number;
}

Thats what i got now, but i have some concerns:

==> it supposed to preview on face 0 and show on face 2 (at least i thought so), but its vice versa.

==> i am not sure if llGetInventoryNumber(INVENTORY_TEXTURE); needed here.

==> preloading is going too fast.

Please correct me if I was wrong?
Is it enough to just swap faces? because the script works in general.

 

integer index;
string name;

default
{
    state_entry()
    {
        llSetTimerEvent(3.0);
    }

    timer()
    {
        integer number = llGetInventoryNumber(INVENTORY_TEXTURE);

    if (number)
    {   
        string name = llGetInventoryName(INVENTORY_TEXTURE, index);
        if (name != "") llSetTexture(name, 2);
        index = (++index) % number;
        llSubStringIndex(name, "") != -1;        
        llSetTexture(name, 0);
    }
    }
}

 

Link to comment
Share on other sites

4 minutes ago, Rolig Loon said:

Don't bother reinventing the wheel.  Use Sendao Goodman's classic script, which I retooled and posted in the LSL Library ages ago >>> 

 

Hello! Thank you very much! Just tried it - fantastic! Very advanced! as i understood it uses even more faces than 1 to preload? Awesome!

But what about my little script? Please help!

Link to comment
Share on other sites

You can preload on as many faces as the prim has less one, so on a cut hollowed cube you will have faces 0 to 7 to play with.

Make a small script that you drop in a prim that tells you what face number was touched using llDetectedTouchFace() so that you know which face is which, and assign these numbers to integer variables at the head of your script.

Preloading a texture is exactly the same as showing it, except that it hasn't happened before (That's just reminded me of a Robin Hitchcock song). There is, however, a complication to consider in the values of the prev, This and next variables because none of them must go outside the valid range of textures found in the prim.

Set the count of textures numTex as already done in your snippet.

integer maxTex = ...

integer this = 0

integer prev

integer next

 

Inside a function which you will be calling regularly

set prev to this - 1 BUT if it is less than 0, then it must be adjusted to the number of textures -1

set next to this + 1 BUT if it is equal to or greater than the count of textures set it to 0

On your main face you show texture number (this).  on the face you chose for the previous texture, show texture number (prev), and on the face chose for the next texture, show texture number (next).

When you adjust the number of the texture to be shown by either incrementing or decrementing it, you have to first adjust it if it is outside the valid range, then you calculate new values for prev and next and likewise adjust them.

 

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

this is just a general something to think about

when we are new to programming then we usually learn to write code in longhand. And longhand is most often the best way for us learn, as longhand tends to be more expressive. Expressive meaning a little more understandable

an example of longhand. Increment and decrement an index, keeping the index within some bounds (magnitude)

integer magnitude = 8;
integer index;   // index in [0..7]
 
increment()
{
   ++index;
   if (index == magnitude)
	index = 0;
}

decrement()
{
   --index;
   if (index == -1)
      index = magnitude - 1;
}

which is fairly understandable code

then as we go along on our scripting journey we sometimes start to see code being written in shorthand like this:

integer magnitude = 8;
integer index;   // index in [0..7]
 
increment()
{
   index = (++index) % magnitude;
}

this above shorthand for increment is found in many languages scripts/source codes

what I will show now (for those reading who don't know) is the similar shorthand for decrement

index = (--index + magnitude) % magnitude;

 

  • Thanks 1
Link to comment
Share on other sites

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