Jump to content

Need help with changing Light color of a prim scripted to be a light emitter


CobraDredd
 Share

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

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

Recommended Posts

I'm running a script that reads a line and then creates light based on the lines in the head. I want to be able to have it rotate thru different colors based on a list variable but not sure how to get it to work. Here is the script if anyone has any input or can point me to a script that already does it I'd be greatful.

 

integer light_s = TRUE;
vector lightcolor = <1.0, 0.255, 1.0>;
float intensity = 1.0;
float radius = 20.0;
float falloff = 0.0;
float glow = 1.0;
 
switchit()
{
    float thisglow = 0.0;
    light_s = !light_s;
    if (light_s)
    {
        thisglow = glow;
    }
    llSetPrimitiveParams([
        PRIM_POINT_LIGHT, light_s, lightcolor, intensity, radius, falloff,
        PRIM_FULLBRIGHT, ALL_SIDES, light_s,
        PRIM_GLOW, ALL_SIDES, thisglow
    ]);
      llSetColor(lightcolor, ALL_SIDES);
}
 
default
{
    state_entry()
    {
      switchit();
    }
 
    touch_start(integer total_number)
    {
        switchit();
    }
}

 

Link to comment
Share on other sites

This line controls the light color:

vector lightcolor = <1.0, 0.255, 1.0>;

so change this to use some variables, such as:

lightcolor = <red, green, black>;

Read from your list which of the three colors you want to change, either red, green, or black. To rotate the color, step the value for the variable corresponding to that color incrementally from 0.0 to 1.0.

Link to comment
Share on other sites

Sorry I should of mentioned I was not a scripter or programmer by trade. I'm rather new to scripting in SL and not sure how to do what you suggested. I have gotten some other details but I keep getting a syntax error for the following code but not sure what the syntax error is.

 

vector lightcolor = (vector)llList2String(AllColors,(integer)llFrand(llGetListLength(AllColors) -1))

 

Link to comment
Share on other sites

vector lightcolor = (vector)llList2String( AllColors, (integer)llFrand( (float)llGetListLength( AllColors ) ) )

 llFrand expects a float.... and it's result will never be the highest value you feed it (always 0 to just short of the value given) so you don't need to subtract 1 =)

ETA:

the third value in a color vector is Blue not black, probably a typo

Link to comment
Share on other sites

I tried that too still get a syntax error. I'm just not familar enough with LSL to know what possible syntax should be for vector.

One thing I forgot to mention is that its telling me the syntax error is immediately after the = sign in this code.

vector lightcolor = (vector)llList2String( AllColors, (integer)llFrand( (float)llGetListLength( AllColors ) ) );

 

Link to comment
Share on other sites

Here is the complete script as is.

 

integer light_s = TRUE;list AllColors =[ "<1.0,1.0,1.0>"," <1.0.1.0,0.0>","<0.0,0.0,1.0>"," <0.0,1.0,1.0,>","<0.0,1.0,0.0>"];vector lightcolor = (vector)llList2String(AllColors,(integerllFrand((float)llGetListLength(AllColors) -1));float intensity = 1.0;float radius = 20.0;float falloff = 0.0;float glow = 1.0; switchit(){    float thisglow = 0.0;    light_s = !light_s;    if (light_s)    {        thisglow = glow;    }    llSetPrimitiveParams([        PRIM_POINT_LIGHT, light_s, lightcolor, intensity, radius, falloff,        PRIM_FULLBRIGHT, ALL_SIDES, light_s,        PRIM_GLOW, ALL_SIDES, thisglow    ]);      llSetColor(lightcolor, ALL_SIDES);} default{    state_entry()    {      switchit();    }     touch_start(integer total_number)    {        switchit();    }}

 

Link to comment
Share on other sites

Oh.   You can't put executable code in a type declaration statement like that.  Take the line that says

vector lightcolor = (vector)llList2String(AllColors,(integerllFrand((float)llGetListLength(AllColors) -1));

and put it as the first line in your switchit function.

BTW, Void is right.  You don't need the -1.

Link to comment
Share on other sites

THIS.................

switchit(){    vector lightcolor = (vector)llList2String(AllColors,(integer)llFrand((float)llGetListLength(AllColors)));    float thisglow = 0.0;    light_s = !light_s;    if (light_s)    {        thisglow = glow;    }    llSetPrimitiveParams([        PRIM_POINT_LIGHT, light_s, lightcolor, intensity, radius, falloff,        PRIM_FULLBRIGHT, ALL_SIDES, light_s,        PRIM_GLOW, ALL_SIDES, thisglow    ]);      llSetColor(lightcolor, ALL_SIDES);}

 :smileywink:

Link to comment
Share on other sites

Hehehehe... You never SAID that.  :smileyvery-happy:

In that case, you need to replace the touch_start event with a timer event (just remove the "touch_start(integer total_number)" and replace it with "timer()" ).  You'll also need to put

llSetTimerEvent(5.0);  //Or however many seconds you want.....

in the state_entry event

Link to comment
Share on other sites

As it's written, you should get white, yellow, blue, or either of two shades of green.  You can change any or all of the color vectors in that list, and you can make the list as long as you like.  Just be sure that each color vector begins and ends with < > brackets and is wrapped in quotes, and that there are commas between elements in the list.

Link to comment
Share on other sites

Thats what I thought also but I'm getting black and some other colors that I can't make out and they aren't going in order either it will flash the first color in the list then a random one in the list then black then sometimes flash the same color several times with alternating black.

Link to comment
Share on other sites

  • 4 years later...

Hi I am trying to apply this to an underglow script for a car, but I keep getting the "error line 2, 20". I tried to follow everything as stated in this topic, but I am surely lost and have missed something.

 

integer light_s = TRUE;
list AllColors =[ "<1.0,1.0,1.0>"," <1.0.1.0,0.0>","<0.0,0.0,1.0>"," <0.0,1.0,1.0,>","<0.0,1.0,0.0>"];
vector lightcolor = (vector)llList2String
float intensity = 1.0;
float radius = 20.0;
float falloff = 0.0;
float glow = 1.0;

switchit()
{
vector lightcolor = (vector)llList2String(AllColors,(integer)llFrand((float)llGetListLength(AllColors)));
float thisglow = 0.0;
light_s = !light_s;
if (light_s)
{
thisglow = glow;
}
llSetPrimitiveParams([
PRIM_POINT_LIGHT, light_s, lightcolor, intensity, radius, falloff,
PRIM_FULLBRIGHT, ALL_SIDES, light_s,
PRIM_GLOW, ALL_SIDES, thisglow
]);
llSetColor(lightcolor, ALL_SIDES);
}

default
{
state_entry()
{
switchit();
llSetTimerEvent(5.0)
}

timer();
{
switchit();
}
}

 

I want to attach this to a HUD control, but i just want to make sure i can get it to work first.

Link to comment
Share on other sites

You're replying to a five year-old thread.

The error you're seeing (which you should in future post in full) is because you're doing this:-

vector lightcolor = (vector)llList2String
  • The line is unterminated.
  • You're type-casting outside of a state.
  • You're using an LSL command (llList2String) outside of a state.

My quick reading of this thread suggests that Rolig identified the mistake carried in from the original poster on Page 2. Look for her expert correction. :)

Link to comment
Share on other sites

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