Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llSetLinkTexture with for loop?

Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-04-2009 18:24
i've only used for loops in scripts i gotten elsewhere so i don't really understand how it works, i have a large number of textures that i wanted to apply to a link set in sequence so i wrote this script to try to do that to apply a texture to a face and then move to the next link when all the faces are covered on the current link.

From: someone
default
{
state_entry()
{
integer link = llGetNumberOfPrims();
integer face = 6;//7 faces on prim starting with 0 so highest index there is 6

integer i;
integer textnum = llGetInventoryNumber(INVENTORY_TEXTURE)-1;//get the number of textures in the inventory, then subtract 1 to get the index for the last one
for ( i = textnum; i > -1; --i)
if(face == -1)//if it passed the lowest face go to the next link and start over
{
face = 6;//7 faces on prim starting with 0 so highest index there is 6
--link;
}
string name = llGetInventoryName(INVENTORY_TEXTURE,i);
string uuid = llGetInventoryKey(name);
llSetLinkTexture(link,uuid,face);
--face;
}
}


i'm using a set of cubes cut to 0.00 and 0.750 and i made sure there's enough faces to hold all the textures. but each time the script starts i just get an error

[18:09] Object: Could not find texture '00000000-0000-0000-0000-000000000000'.

i tried applying it with just the name but i was getting

[18:04] Object: Could not find texture ''.

can anyone spot the problem and help me fix it? thanks
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-04-2009 19:46
Do you have full copy/mod/transfer perms on the textures in the object's inventory? If not, then llGetInventoryKey will return NULL_KEY. Of course, that shouldn't affect llGetInventoryName.....
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-04-2009 19:50
yes they're full perm sculpt maps, i'm trying to use it to display all the maps so they'll already be loaded as i flip thru the types
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-04-2009 20:08
sorta figured out what i was doing wrong, was missing a set of brackets to determine what needed to be done with the loop, so i guess it was causing the index number to not change and i also reverved the increment calls (--i changed to i--)

From: someone

default
{
state_entry()
{
integer link = llGetNumberOfPrims();
integer face = 6;
integer textnum = llGetInventoryNumber(INVENTORY_TEXTURE)-1;
integer i;
for (i = textnum; i > -1; i--){
if(face == -1)
{
face = 6;
link--;
}
string name = llGetInventoryName(INVENTORY_TEXTURE,i);
string uuid = llGetInventoryKey(name);
llSetLinkTexture(link,uuid,face);
face--;}
llOwnerSay("done";);
}
}


worked perfectly
_____________________
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-04-2009 20:14
Yay. :)
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-04-2009 20:48
played with it some more so i could view them all on one side, and used the XY setup script to shape the prims

From: someone

list faces = [3,7,4,6,1];
default
{
state_entry()
{
integer link = llGetNumberOfPrims();
integer face = 0;
integer textnum = llGetInventoryNumber(INVENTORY_TEXTURE)-1;
integer i;
for (i = textnum; i > -1; i--){
if(face == 5)
{
face = 0;
link--;
}
string name = llGetInventoryName(INVENTORY_TEXTURE,i);
string uuid = llGetInventoryKey(name);
integer facenum = llList2Integer(faces,face);
llOwnerSay("link " + (string)link + " face " + (string)facenum);
llSetLinkTexture(link,uuid,facenum);
face++;}
llOwnerSay("done";);
}
}
_____________________
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
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-04-2009 21:19
From: Ruthven Willenov
..and i also reverved the increment calls (--i changed to i--)

Just as a side-note, if you're not using the variable in a function call or as part of some larger equation, this bit really doesn't matter - it's the same either way.

If you do this, the 'DoStuff' routine will get passed a 0.
i = 1; DoStuff (--i);

If you do this, the 'DoStuff' routine will get passed a 1.
i = 1; DoStuff (i--);

Either way, i is equal to 0 after DoStuff returns.

As the last bit of a 'for' statement, using pre- or post- doesn't matter.