Syle Devin Posted January 6, 2013 Share Posted January 6, 2013 So I've been trying to figure out how to make a script that will change a prims texture, color to specific setting each time an object is touched. The problem is that I cannot find anything on how to use the touch_start multiple times or is there some sort of if touched do this. Such as something like this which I got from a script that changes texture from a menu but I can't find anything on the wiki about how to change it to set color on touch. Is there some sort of way for the script to check what the color is currently set to and then to change it to the next one? listen(integer channel,string name, key id,string message) { if(id==gUser) { if(message=="Blue") { llSetLinkColor(17,<64,76,148>*0.00392,ALL_SIDES); return; } if(message=="Skyblue") { llSetLinkColor(17,<43,238,255>*0.00392,ALL_SIDES); return; } Link to comment Share on other sites More sharing options...
Dora Gustafson Posted January 6, 2013 Share Posted January 6, 2013 Make a list of colors, say:list colors = [red, green, blue]; and have an index i, in this case i can take the values: 0,1,2 Each time you touch, you increment the index modulus 3 in this case:i=(i+1)%3; or: i=++i%3; then use the color from the list indexed by i :smileysurprised::smileyvery-happy: Link to comment Share on other sites More sharing options...
Syle Devin Posted January 6, 2013 Author Share Posted January 6, 2013 I kind of get what your saying but sadly I don't really know enought to fully integrate those parts myself. I'm quiet the begginer when it comes to scripting. Also in the list colors would I just list the color for example "256,256,256","1,1,1","0,0,0" and so on. Link to comment Share on other sites More sharing options...
Ron Khondji Posted January 6, 2013 Share Posted January 6, 2013 Something like this is what you´re looking for: list colors = [ <0.0, 0.0, 1.0>, // blue <1.0, 0.0, 0.0>, // red <0.0, 1.0, 0.0>, // green <1.0, 1.0, 0.0> // yellow ];integer count;default { touch_end(integer total_number) { llSetColor(llList2Vector(colors, count), ALL_SIDES); ++count; if (count >= llGetListLength(colors)) count = 0; }} Link to comment Share on other sites More sharing options...
Syle Devin Posted January 6, 2013 Author Share Posted January 6, 2013 Thanks so much! I had just found a script that was almost like that but it was used to changed textures using uuid's. I tried to change it to work with colors but it wouldn't work when I jsut set the "llSetTexture" to "llSetColor". How come? I got the error right after ALL_SIDES (8,64) : ERROR : Function call mismatches type of number of arguments list Textures = [<255.0,255.0,0>,<255.0,125.0,0>];integer Texture;default{ touch_start (integer t) { llSetColor (llList2Key (Textures, Texture++), ALL_SIDES); Texture %= llGetListLength (Textures); }} Also I tried to add this... after the llSetColor so that I could change a linked prim. The script saves but it doesn't affect the linked prim. llSetLinkColor(2,llList2Vector(colors, count),1); Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 6, 2013 Share Posted January 6, 2013 Because your list elements (correctly) are vectors, not keys. You should be using llList2Vector, not llList2Key. And when you did it correctly with your second try, you introduced a new undefined variable, count, where you had been using Texture before. Also, you may be trying to change the wrong child prim. Do you really want to color prim #2? Link to comment Share on other sites More sharing options...
Syle Devin Posted January 6, 2013 Author Share Posted January 6, 2013 Oh sorry I meant that I tried to add that into the script that ron posted. Yes I checked the prim link number with a script so I am sure, plus it is the only other prim linked to the main object. Everything seems to be correct it just doesn't effect it. Edit: Ah I forgot to notice that I didn't change the side that would change color, it needed to be ALL_SIDES instead of 1. I got the linked color change working. Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 6, 2013 Share Posted January 6, 2013 You added it, or replaced what was there before? It should look like this: list colors = [ <0.0, 0.0, 1.0>, // blue <1.0, 0.0, 0.0>, // red <0.0, 1.0, 0.0>, // green <1.0, 1.0, 0.0> // yellow ];integer count;default { touch_end(integer total_number) { llSetLinkColor(2,llList2Vector(colors, count), ALL_SIDES); ++count; if (count >= llGetListLength(colors)) count = 0; }} Or, better list colors = [ <0.0, 0.0, 1.0>, // blue <1.0, 0.0, 0.0>, // red <0.0, 1.0, 0.0>, // green <1.0, 1.0, 0.0> // yellow ];integer count;integer gNumCol;default { state_entry() { gNumCol = (colors !=[]); // Same as llGetListLength(colors) } touch_end(integer total_number) { llSetLinkColor(2,llList2Vector(colors, ++count%gNumCol), ALL_SIDES); }} Link to comment Share on other sites More sharing options...
Dora Gustafson Posted January 7, 2013 Share Posted January 7, 2013 I ask myself: better? In what way? Size? Speed? Effectiveness? Portability? Readability? Comprehensibility? This piece of code: gNumCol = (colors !=[]); Looks like it is written by the master of unreadable code It looks like a work around for something that do not need to be worked around It gives no clue to what it does or what it is supposed to do. Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 7, 2013 Share Posted January 7, 2013 That's a fairly standard shortcut, Dora, inherited from Strife, Void, and others. And I explained what it does in a comment line for the OP. It's slightly faster than executing llGetListLength. That's not really my point about "slightly better", though. I was looking at the fact that there's no need to call llGetListLength each time you touch the object, and there's no need to use an if test to check and reset the count variable each time it becomes bigger than llGetListLength. It's more efficient to get the length of the list one time in state_entry, and to increment count and keep it in bounds with the modulo operator. Link to comment Share on other sites More sharing options...
Recommended Posts
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