- Forums
- :
- Creation Forum
- :
- LSL Scripting
- :
- Re: Touch Color Changer?
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Touch Color Changer?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-06-2013 12:37 AM
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;
}
Re: Touch Color Changer?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Reply to Syle Devin - view message
01-06-2013 03:52 AM
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
![]()
![]()
![]()
Re: Touch Color Changer?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Reply to Dora Gustafson - view message
01-06-2013 12:00 PM - edited 01-06-2013 12:04 PM
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.
Re: Touch Color Changer?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Reply to Syle Devin - view message
01-06-2013 12:30 PM
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;
}
}
Re: Touch Color Changer?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Reply to Ron Khondji - view message
01-06-2013 12:48 PM - edited 01-06-2013 12:59 PM
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);
Re: Touch Color Changer?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Reply to Syle Devin - view message
01-06-2013 01:11 PM - edited 01-06-2013 01:14 PM
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?
Re: Touch Color Changer?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Reply to Rolig Loon - view message
01-06-2013 01:34 PM - edited 01-06-2013 01:47 PM
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.
Re: Touch Color Changer?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Reply to Syle Devin - view message
01-06-2013 01:53 PM
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); } }
Re: Touch Color Changer?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Reply to Rolig Loon - view message
01-07-2013 04:27 AM
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.
Re: Touch Color Changer?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Reply to Dora Gustafson - view message
01-07-2013 06:36 AM - edited 01-07-2013 06:37 AM
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.

