Jump to content

List and indexs help


Saiko
 Share

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

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

Recommended Posts

Ok first of all ill explain what im doing, im making a texture changer hud that allow me to select different faces of a single prim and place the face number into a list, then when i click the color i want to change lets say red, it sends that list along with the color name to the receiver object, in the receiver object it parses it to a new list, i have a list for each color with the same amount of texture uuids that goes in each face. i want to make is how can i use the same list i get from the hud to use it to change the texture of that index to that exact side example.

 

Lets say i get this from the hud

list sides = ["1", "2", "5", "7"];

So i want to use those for index and sides

and this is the list of textures (wood texture uuid for the example):

list RED = [

"89556747-24cb-43ed-920b-47caed15465f",         // index 0 for face 0
"89556747-24cb-43ed-920b-47caed15465f",         // index 1 for face 1
"89556747-24cb-43ed-920b-47caed15465f",         // index 2 for face 2
"89556747-24cb-43ed-920b-47caed15465f",         // index 3 for face 3
"89556747-24cb-43ed-920b-47caed15465f",         // index 4 for face 4
"89556747-24cb-43ed-920b-47caed15465f",         // index 5 for face 5
"89556747-24cb-43ed-920b-47caed15465f",         // index 6 for face 6
"89556747-24cb-43ed-920b-47caed15465f"];        // index 7 for face 7

 

so what i need to figure out is how can i get to change the texture of lets say of  ["1", "2", "5", "7"]; to those especific sides and using the same numbers as index.

 

at the moment i just made a for loop like this:

 

integer length = llGetListLength(sides);
integer x;
for (x = 0; x < length; x++)
{
llSetTexture(llList2String(RED, x),llList2Integer(sides, x));
}

and yeah it works but only if all the faces are selected because if the list is just a few faces it will change it only to the wrong index because of the  lenght and if i use another loop it will cycle each texture every time.

 

I dont know if i explained myself clear or if there is another way i could make this work, like send the uuid directly from the hud and parse it to a list with the same lenght as the sides one, but still i get into the same trouble of how to get each texture from the especific index to a new list.

 

any ideas?

 

Thanks in advance for any help you can provide me into pointing me in the right direction.

 

 

Link to comment
Share on other sites


Jack Jaehun wrote:

try this:

llSetTexture(llList2String(RED,
llList2Integer(sides, x)
),llList2Integer(sides, x));

OMG thank you so much, it made it, works like a charm now!

i feel dumb for not seeing it and making it loop in a wrong way. thank you again!!!

Link to comment
Share on other sites

In situations like this using a strided list is more efficient. It would look like something like this

list sides = [0, "", 1, "89556747-24cb-43ed-920b-47caed15465f", 2, "89556747-24cb-43ed-920b-47caed15465f", 3, "",...]

The idea is you list both side and texture to assign to it in the same list next to each other and for those sides that do not have textures just put an empty string "".

Then your code would look like this:

integer length = llGetListLength(sides);
integer i;
for (i =1; i < length; i+=2)
  {

  if(llList2String(sides,i) ! = "")
    llSetTexture(llList2String(sides,i),llList2Integer(sides, i-1));
  }

Please also note that defining a loop index variable as "x" is a bad programming style. Commonly, letters, i, j,k are used.

 

  • Like 1
Link to comment
Share on other sites


Ela Talaj wrote:

In situations like this using a strided list is more efficient. It would look like something like this

list sides = [0, "", 1, "89556747-24cb-43ed-920b-47caed15465f", 2, "89556747-24cb-43ed-920b-47caed15465f", 3, "",...]

The idea is you list both side and texture to assign to it in the same list next to each other and for those sides that do not have textures just put an empty string "".

Then your code would look like this:

integer length = llGetListLength(sides);

integer i;

for (i =1; i < length; i+=2)

  {

  if(llList2String(sides,i) ! = "")

    llSetTexture(llList2String(sides,i),llList2Integer(sides, i-1));

  }

Please also note that defining a loop index variable as "x" is a bad programming style. Commonly, letters, i, j,k are used.

 

Im pretty new to programming and only been trying to do things since a few weeks, thanks for the advice on the loop, and well i made the hud with a lot of reading and seeing examples and a some help as well of people, and yes i thought of strided list when i read about them, but since the users are selecting which face will change and that list of sides will be send to the receiver and parsed there to a new list i thought it was better this way, also because of the many color lists, im sure there would be better ways to do it, but i dont know how lol, it seems to be working fine

And Thanks for the example, i'm sure i will be using it for something at some point

Link to comment
Share on other sites

You're correct not to use a strided list if I understand correctly that the set of sides to paint is determined dynamically, whereas the textures with which to paint them is static.

I realize that this is just an example, but if the same textures are often repeated, it may be worthwhile to create another level of indirection: a "texture directory list" of unique texture keys, and have the color-by-numbers lists (RED in the example) instead contain only the integer indices into that texture directory list.

The reason for obsessing here is that keys take up just ridiculously large amounts of memory in a list. There are also ways to compress them when memory is tight, but it's almost always a win to avoid storing the same key more than once.

  • Like 1
Link to comment
Share on other sites


Qie Niangao wrote:

You're correct not to use a strided list if I understand correctly that the set of sides to paint is determined dynamically, whereas the textures with which to paint them is static.

I realize that this is just an example, but if the same textures are often repeated, it may be worthwhile to create another level of indirection: a "texture directory list" of unique texture keys, and have the color-by-numbers lists (RED in the example) instead contain only the integer 
indices
 into that texture directory list.

The reason for obsessing here is that keys take up just ridiculously large amounts of memory in a list. There are also ways to compress them when memory is tight, but it's almost always a win to avoid storing the same key more than once.

yes it is dynamically, depends on the users choices,  there is not repeated keys though all are different textures in what im doing, but is good to know now because maybe ill run into objects that probably use dozens of textures that could be the same.

 

Thanks for the help and advices from each of you, im fascinated with scripting now.

Link to comment
Share on other sites

There is no difference whether a strided list is static or dynamic. It never takes more OS resources than a regular list for a simple reason that for a compiler there is no such thing as a strided list, it is a purely logical concept for a programmer to group items in regular lists.

Link to comment
Share on other sites

Yes, but as Saiko explained, the information in the dynamic list is generated through user interaction--it doesn't yet exist at compile time (different from what's in the sample code)--so there's no way to populate a strided list in advance, whereas the static information must be stored somewhere in the code, in a constant.

Link to comment
Share on other sites

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