Jump to content

Color tiles script issue


Tattooshop
 Share

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

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

Recommended Posts

Hello everybody!

I have strange script issue. this is a random color tiles script. it should show a random color from the list in a collision, but at times black color skips and it has no black RGB in the list.

So what's wrong with it?

list color_list = [ 

    < 1, 0, 0 > , 
    < 1, 1, 0 > , 
    < 1, 1, 1 > 

    // Add more colors if you want
]; 

integer random_integer(integer min, integer max)
{
    return min + (integer) llFrand(max - min + 1);
}

default
{
    state_entry()
    {
        llSetColor( < 1, 1, 1 > , ALL_SIDES);
        
        llSetTexture("5748decc-f629-461c-9a36-a35a221fe21f", ALL_SIDES); // White texture UUID

    }
    collision_start(integer a)
    {
        llSetColor(llList2Vector(color_list, random_integer(0, llGetListLength(color_list))), ALL_SIDES);
        llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 1.0]);
    }
    collision_end(integer a)
    {
        llSetColor( < 1, 1, 1 > , ALL_SIDES); 
        llSetPrimitiveParams([PRIM_GLOW, ALL_SIDES, 0.0]);
    }
}

 

Link to comment
Share on other sites

If the list index is out-of-bounds, it will return whatever the default (zero) value is for that type. ZERO_VECTOR is equal to black color.

List indexes start from 0. Your last index is 2. llGetListLength returns 3 because your list has 3 elements. Your random_integer adds 1 to the result.

random_integer(0, 3) returns (0 + llFrand(3 - 0 + 1), which means the highest result is (integer)3.99999 or 3. That's not a valid index and you get ZERO_VECTOR.

  • Thanks 1
Link to comment
Share on other sites

4 minutes ago, Wulfie Reanimator said:

If the list index is out-of-bounds, it will return whatever the default (zero) value is for that type. ZERO_VECTOR is equal to black color.

List indexes start from 0. Your last index is 2. llGetListLength returns 3 because your list has 3 elements. Your random_integer adds 1 to the result.

random_integer(0, 3) returns (0 + llFrand(3 - 0 + 1), which means the highest result is (integer)3.99999 or 3. That's not a valid index and you get ZERO_VECTOR.

Hi thanks a lot for answering! but there were about ten colors on the list, and it still happened. I removed some colors to make sure. and what to do in this case?

Link to comment
Share on other sites

2 hours ago, Wulfie Reanimator said:

Your random_integer adds 1 to the result.

random_integer(0, 3) returns (0 + llFrand(3 - 0 + 1), which means the highest result is (integer)3.99999 or 3. That's not a valid index and you get ZERO_VECTOR.

 return min + (integer) llFrand(max - min);

I just deleted 1 and now everything is ok! it was so easy, I feel stupid. thanks! 😀

Link to comment
Share on other sites

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