Reply
Member
Syle Devin
Posts: 183
0 Kudos

Touch Color Changer?

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;
            }

 

 

Dora Gustafson
Posts: 1,738
Registered: ‎10-05-2009
0 Kudos

Re: Touch Color Changer?

Reply to Syle Devin - view message

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::smileyhappy::smileyvery-happy:

Member
Syle Devin
Posts: 183
0 Kudos

Re: Touch Color Changer?

[ Edited ]

Reply to Dora Gustafson - view message

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.

Member
Ron Khondji
Posts: 191
0 Kudos

Re: Touch Color Changer?

Reply to Syle Devin - view message

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;
    }
}

 

Member
Syle Devin
Posts: 183
0 Kudos

Re: Touch Color Changer?

[ Edited ]

Reply to Ron Khondji - view message

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);

 

Rolig Loon
Posts: 22,704
Registered: ‎10-05-2009
0 Kudos

Re: Touch Color Changer?

[ Edited ]

Reply to Syle Devin - view message

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?

Not as dumb as I look
Member
Syle Devin
Posts: 183
0 Kudos

Re: Touch Color Changer?

[ Edited ]

Reply to Rolig Loon - view message

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.

Rolig Loon
Posts: 22,704
Registered: ‎10-05-2009
0 Kudos

Re: Touch Color Changer?

Reply to Syle Devin - view message

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);
    }
}

 

 

Not as dumb as I look
Dora Gustafson
Posts: 1,738
Registered: ‎10-05-2009
0 Kudos

Re: Touch Color Changer?

Reply to Rolig Loon - view message

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.

Rolig Loon
Posts: 22,704
Registered: ‎10-05-2009
0 Kudos

Re: Touch Color Changer?

[ Edited ]

Reply to Dora Gustafson - view message

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.

Not as dumb as I look