Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Slideshow Stops After 4 Textures

Lucien Feldragonne
Registered User
Join date: 4 Jan 2010
Posts: 2
01-13-2010 05:18
Hi guys,

I made a slideshow object and threw about 20 snapshots in there along with this code I kinda hacked together from examples online. It works great, for exactly 4 textures, then it just stops cycling them. Any tips would be MOST appreciated :D

Lucien


integer tex_count = 0;


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

timer()
{
integer count = llGetInventoryNumber( INVENTORY_TEXTURE );
if( count == 0 )
return;
if( tex_count > count - 1 )
tex_count = 0;

llSetTexture( llGetInventoryName(INVENTORY_TEXTURE, tex_count), 0);
++tex_count;
}
}
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-13-2010 05:52
Off the top of my head and untested, but this ought to work.....

CODE

integer count;
default
{
touch_start(integer num)
{
tex_cnt = llGetInventoryNumber(INVENTORY_TEXTURE);
llSetTimerEvent(30);
}

timer()
{
if (--tex_cnt)
{
llSetTexture( llGetInventoryName(INVENTORY_TEXTURE, count), 0);
++count;
}
else
{
llSetTimerEvent(0);
}
}

}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
Try...
01-13-2010 06:45
if ( tex_count > (count - 1 ) )

..
_____________________
So many monkeys, so little Shakespeare.
Lucien Feldragonne
Registered User
Join date: 4 Jan 2010
Posts: 2
01-13-2010 07:35
Thank you all for your help. Unfortunately I made an unforseen mistake that I FINALLY realized...

I had taken a bunch of snapshots in the same location. The snapshot's default names were all exactly the same, even though they were different pictures. What I am assuming happened is when I called llGetInventoryNumber( INVENTORY_TEXTURES ) it was counting all of the snaps I had that were named exactly the same as a single texture, therefore it was calling only the first of those over and over again, it had no way to distinguish between them, which is why it always looked "stuck". Once it got past those 16 snaps that were all named the same it started working correctly again.

So, just FYI if anyone runs into this issue. If you're cycling textures, make sure they all have unique names :D

Thanks again,

Lucien
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-13-2010 07:43
How does
CODE
if (--tex_cnt)
work?
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-13-2010 08:19
From: Innula Zenovka
How does
CODE
if (--tex_cnt)
work?


it counts down, and if it tests TRUE it works, else is FALSE. the problem with that is, it will never use index 0 because 0 is FALSE
CODE


integer num = 0;
integer count;

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

timer()
{
count = llGetInventoryNumber(INVENTORY_TEXTURE);
if(count){
llSetTexture( llGetInventoryName(INVENTORY_TEXTURE, (++num)%count, 0);
}
else
{
llSetTimerEvent(0);
}
}
changed(integer c)
{
if(c & CHANGED_INVENTORY)
{
count = llGetInventoryNumber(INVENTORY_TEXTURE);
if(count)
{
llSetTimerEvent(30.0);
}
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-13-2010 09:00
If you're keeping score at home ..... My suggested script turns on at a touch, displays the textures in order and then shuts off the timer and waits for someone to touch the object again. Ruthven's nice script continues indefinitely, looping through all of the slides and starting over again. That's the magic of using (++num)%count to identify which texture is displayed. If you want another variation on that theme, you could display random textures indefinitely by replacinging (++num)%count with (integer)llFrand(count). Many variations on the theme. :D
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-13-2010 09:42
From: Rolig Loon
Ruthven's nice script continues indefinitely, looping through all of the slides and starting over again.

it also turns off as it should if there's no textures in the object's contents. and the changed event turns it back on if there was some added. probably need to play with some integers so that it doesn't restart the timer each time textures are added if there was already some in there. not awake enough to figure out the logic needed for that lol
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-13-2010 09:51
From: Ruthven Willenov
it counts down, and if it tests TRUE it works, else is FALSE. the problem with that is, it will never use index 0 because 0 is FALSE

:o I told you it was untested. It will work fine, except that I forgot to write two lines in the touch_start event. Let's do that again, cleaned up ....

CODE

integer count;
integer tex_cnt; //I forgot to make tex_cnt global before :o
default
{
touch_start(integer num)
{
tex_cnt = llGetInventoryNumber(INVENTORY_TEXTURE);
llSetTexture(llGetInventoryName(INVENTORY_TEXTURE,0),0);
// This shows slide zero immediately, instead of waiting 30 seconds for the timer to kick in
count = 1; //This will display the next slide (#1) when the timer starts

llSetTimerEvent(30);
}

timer()
{
if (--tex_cnt)
{
llSetTexture( llGetInventoryName(INVENTORY_TEXTURE, count), 0);
++count;
}
else
{
llSetTimerEvent(0);
}
}

}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
01-13-2010 10:44
From: Innula Zenovka
How does
CODE
if (--tex_cnt)
work?

It says "subtract one from tex_cnt then do the following if it's not zero."

An "if (tex_cnt--)" would be "see if tex_cnt is non-zero, subtract one from it then do the following if it wasn't zero."
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-13-2010 11:34
Thanks for the explanations, all.. now I get it.
Waterlilly Nightfire
Registered User
Join date: 31 Jan 2009
Posts: 1
01-13-2010 12:37
From: Lucien Feldragonne
Thank you all for your help. Unfortunately I made an unforseen mistake that I FINALLY realized...

I had taken a bunch of snapshots in the same location. The snapshot's default names were all exactly the same, even though they were different pictures. What I am assuming happened is when I called llGetInventoryNumber( INVENTORY_TEXTURES ) it was counting all of the snaps I had that were named exactly the same as a single texture, therefore it was calling only the first of those over and over again, it had no way to distinguish between them, which is why it always looked "stuck". Once it got past those 16 snaps that were all named the same it started working correctly again.

So, just FYI if anyone runs into this issue. If you're cycling textures, make sure they all have unique names :D

Thanks again,

Lucien

hmm, this shouldn't have been a problem because if you drop more than one item with the same name into the contents of an object, it automatically adds numbers to the names
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-13-2010 12:50
From: Ruthven Willenov
it also turns off as it should if there's no textures in the object's contents. and the changed event turns it back on if there was some added. probably need to play with some integers so that it doesn't restart the timer each time textures are added if there was already some in there. not awake enough to figure out the logic needed for that lol

If you want to continue displaying the slides in sequence even as you are adding or removing textures from inventory, you'll have to build in some way to keep track of the texture names as they are displayed. Then, check to see whether the new slide is listed before or after it in inventory and adjust the counter as necessary to show whatever slide should be next. This version below compiles OK, but I can't get in world to test it, so I can't swear that I haven't messed up a counter. (I also haven't made it as nice and compact as it might be.) Still, I think the approach ought to work. ..... maybe. :rolleyes:

CODE

integer num = 0;
integer count;
string curr_tex;
list tex_list = [];

default
{
state_entry()
{
count = llGetInventoryNumber(INVENTORY_TEXTURE);
integer i;
for (i=0;i<=count;++i)
{
tex_list += (list)llGetInventoryName(INVENTORY_TEXTURE,i);
}
llSetTimerEvent(30.0);
}

timer()
{
count = llGetInventoryNumber(INVENTORY_TEXTURE);
if(count)
{
curr_tex = llGetInventoryName(INVENTORY_TEXTURE, (++num)%count);
llSetTexture( curr_tex, 0);
}
else
{
llSetTimerEvent(0);
}
}

changed(integer c)
{
if(c & CHANGED_INVENTORY)
{
list new_tex_list = [];
integer old_cnt = count;
integer old_pos = llListFindList(tex_list, [curr_tex]);
count = llGetInventoryNumber(INVENTORY_TEXTURE);
integer i;
for (i=0;i<=count;i++)
{
new_tex_list += (list)llGetInventoryName(INVENTORY_TEXTURE,i);
}
integer new_pos = llListFindList(new_tex_list, [curr_tex]);
if(count)
{
if(new_pos < old_pos)
{
--num;
}
llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, num%count),0);
tex_list = new_tex_list;
llSetTimerEvent(30.0);
}
}
}
}




ETA: I did mess up a counter, but just fixed it. Still no guarantees. ;) BTW, This method is going to fail if you add or delete more than one texture at a time, because you need to give the script time to figure out where curr_tex sits in the queue of textures in inventory each time you change it.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at