Jump to content
LoganNJ1013

Sync prim face color with prin projector light

Recommended Posts

Hello.  First let me say I'm still pretty new to building, scripting, etc., so I may be a little naive, but...

Okay, let me try to explain what I've got so far....First, I have a link set of lights (prims)...each prim has a script that changes to one of a set group of colors.  I've added an invisible prim as the root which acts as switch for all of the lights with the same script inside.  So each prim color can be changed individually AND they'll all change to the SAME color if the root prim is touched instead.

I've also found and added a script that turns the prim "projector" light on and off along with "full bright"....also by touch.  This only works in the individual lights, not as a set via the root prim, which I'm fine with.

All of this works and works together beautifully.  The only thing I'm looking for now is a way to synchronize the color of the projected light with the chosen color of the prim.  So if I choose to make all the lights blue, then click them all to "turn them on", I'd like the projector light to turn on blue automatically as well.

Not sure if that's even possible...or if it is, whether or not that would conflict with any of the other currently working scripts.  But any help or advice....or scripts, lol...would be greatly appreciated.

Thank you!

Share this post


Link to post
Share on other sites

Well, I am not entirely sure i got all that. Firstly you do not need all those scripts, one, possibly two would have sufficed. If you create a phantom cone from the projector to the screen or what ever it is you can notch the transparent level up and colour that. You will have to use glow maybe/or full light as well to give the effect. I think that is what you are on about.

Share this post


Link to post
Share on other sites

Hi Steph.  Thanks for the reply.  It's true there may be a way to do what I want with just one script, or combining the two I've used, but I just don't know enough yet....and it's working perfectly at the moment so I don't want to stray too far...unless anyone might be able to suggest something better with the same results.

However, I do know exactly what I want to do next...and how to do it.  What I'm looking for, I guess, is an easier way to do it.  I'm just hoping there's a script out there...or someone who would know how to write one (if SL is even capable of it)...that will automatically sync the color of the projector light with whatever color the prim may be at the time just by touch.

I'm attaching some example pics...

- The first (blue) and second (multi-colored) are the "color script"...one click on the the root prim (the ball) will make them all one color, or clicking each individually will change just the color of that prim.

- The third is the "light script"...one click on the individual prim will turn on BOTH full bright and AND the prim's "projector" light, while still offering the color options from the first script. (This script only works individually...placing it in the root prim will not turn the rest on or off)

What I'm looking for now is something that, while still doing all of the above, will actually make the light automatically shine the same color that the prim happens to be just by clicking, without having to go into each one and manually change it every time I change the color of the prim with the "color script".  Using the third pic as an example, one click "turns it on", making it full bright and shining the projector light....but the light is white.  I'd like it to be green to coincide with the current prim color.

I know that's all probably just as "wordy", but I'm just trying to give as much info as I can.  Thanks.

BridgeLights1.png

BridgeLights2.png

BridgeLights3.png

Share this post


Link to post
Share on other sites
Posted (edited)
4 hours ago, LoganNJ1013 said:

 

Use a link message. secondlife.com/wiki/LlSetPrimitiveParams#llSetLinkPrimitiveParamsFast

There is an example lower down the page.

Edited by steph Arnott

Share this post


Link to post
Share on other sites

Thanks again.  It looks to me like those like may help in linking all the prims to act the same way...which may be of use at some point.  And again, I'm no expert, so reading them is another language to me.  I need to know what they mean.

Right now, I just want to get one prim to work at a time...is there a way get a point light to read the color of the prim and use it every time as the color of the prim changes....without having to manually change point light parameters in the script or in the prim?

Share this post


Link to post
Share on other sites

Yes, you can grab the color of any face on any link with llGetLinkPrimitiveParams, using its PRIM_COLOR parameter.  Once you have that information, you can apply it anywhere else, including the color vector for your PRIM_POINT_LIGHT.

Share this post


Link to post
Share on other sites
Posted (edited)

Hey @LoganNJ1013! It's usually best to just post whatever script(s) you have already so we can give better examples/explanations. From your explanation it sounds like all of these lights are separate from each other and not a single linkset. To synchronize the colors between all of these is going to be a bit complicated for a total beginner, and I would suggest linking them all together and learning to use things like llSetLinkColor or llSetLinkPrimitiveParamsFast (for things that can't be changed with another function, like lights).

But, let's take "setting prim colors" as an example. You could do it like this in a linkset of 5 prims:

llSetLinkColor(2, <1.0, 0.808, 0.4>, ALL_SIDES);
llSetLinkColor(3, <1.0, 0.808, 0.4>, ALL_SIDES);
llSetLinkColor(4, <1.0, 0.808, 0.4>, ALL_SIDES);
llSetLinkColor(5, <1.0, 0.808, 0.4>, ALL_SIDES);

It's gonna make the linkset look like this (white box is the "root"): http://puu.sh/CU7qP/3958d87cbe.png

It's important to know that these colors are not set at the same time. The script will change one prim and then wait until the sim lets it use another function (to put it simply). If the sim is laggy, the wait could be noticeable. Alternatively, you could set the color of all 4 prims at the same time with one function, using llSetLinkPrimitiveParamsFast:

llSetLinkPrimitiveParamsFast(1,[
    PRIM_LINK_TARGET, 2, PRIM_COLOR, ALL_SIDES, <1.0, 0.808, 0.4>, 1,
    PRIM_LINK_TARGET, 3, PRIM_COLOR, ALL_SIDES, <1.0, 0.808, 0.4>, 1,
    PRIM_LINK_TARGET, 4, PRIM_COLOR, ALL_SIDES, <1.0, 0.808, 0.4>, 1,
    PRIM_LINK_TARGET, 5, PRIM_COLOR, ALL_SIDES, <1.0, 0.808, 0.4>, 1]);

You can probably see the similarities pretty easily, except there's a couple new things.

  1. The function takes two things: a link number, and a list of parameters with expected values after each one.
    1. By default, the list is applied to the specified link number.
    2. The PRIM_LINK_TARGET must be followed by an integer number, indicating a new link number for the following parameters.
    3. If you look at the second table on the wiki page, you can see this row: ed9f4f5493.png
      It tells you what parameters (the type, and a descriptive name hint) should follow PRIM_COLOR, including PRIM_COLOR itself.
  2. You can split lines into multiple parts without causing issues, just don't forget a comma if you're splitting up a list, and don't forget the closing brackets and semicolon.

You can add more parameters to this, such as "full bright" and a light source, like...

77e035fee8.png

llSetLinkPrimitiveParamsFast(1,[
    PRIM_LINK_TARGET, 2,
        PRIM_COLOR,         ALL_SIDES, <1.0, 0.808, 0.4>, 1.0,
        PRIM_POINT_LIGHT,   TRUE, <1.0, 0.808, 0.4>, 1.0, 10.0, 0.75,
        PRIM_FULLBRIGHT,    ALL_SIDES, TRUE,
    PRIM_LINK_TARGET, 3,
        PRIM_COLOR,         ALL_SIDES, <1.0, 0.808, 0.4>, 1.0,
        PRIM_POINT_LIGHT,   TRUE, <1.0, 0.808, 0.4>, 1.0, 10.0, 0.75,
        PRIM_FULLBRIGHT,    ALL_SIDES, TRUE,
    PRIM_LINK_TARGET, 4,
        PRIM_COLOR,         ALL_SIDES, <1.0, 0.808, 0.4>, 1.0,
        PRIM_POINT_LIGHT,   TRUE, <1.0, 0.808, 0.4>, 1.0, 10.0, 0.75,
        PRIM_FULLBRIGHT,    ALL_SIDES, TRUE,
    PRIM_LINK_TARGET, 5,
        PRIM_COLOR,         ALL_SIDES, <1.0, 0.808, 0.4>, 1.0,
        PRIM_POINT_LIGHT,   TRUE, <1.0, 0.808, 0.4>, 1.0, 10.0, 0.75,
        PRIM_FULLBRIGHT,    ALL_SIDES, TRUE
]);

Now each linked prim will be the same color, be set to full-bright, and emit light matching the prim's color. Hopefully this makes llSetLinkPrimitiveParamsFast look less intimidating. You don't necessarily have to look at the biggest table in the wiki page, it's the same as the second table but with more descriptions added.

P.S. And just to make everything more readable and harder to mess up, you can use a saved list since the "prim color/light/fullbright" is the same for each prim:

list parameters = [PRIM_COLOR, ALL_SIDES, <1.0, 0.808, 0.4>, 1.0, PRIM_POINT_LIGHT, TRUE, <1.0, 0.808, 0.4>, 1.0, 10.0, 0.75, PRIM_FULLBRIGHT, ALL_SIDES, TRUE];

llSetLinkPrimitiveParamsFast(1,
    [PRIM_LINK_TARGET, 2] + parameters +
    [PRIM_LINK_TARGET, 3] + parameters +
    [PRIM_LINK_TARGET, 4] + parameters +
    [PRIM_LINK_TARGET, 5] + parameters );

It's important for me to point the new things out again: You cannot put lists within lists in LSL, so instead I'm adding the list [PRIM_LINK_TARGET, X] with the list of parameters I want for each light, then adding the next to that, and so on, until each prim has its own parameters.

Edited by Wulfie Reanimator
  • Thanks 1

Share this post


Link to post
Share on other sites

@Rolig Loon and @Wulfie Reanimator  Thank you both for your replies. 

That's great news, Rolig!  I guess the question is how?  Where would those commands fit into a script?

Wulfie, right now it IS a link set...but the color script I'm using works for both the set AND individually...which is something I like and want to keep.  I'm using a second script (which only works on the individual parts, which I'm ok with...doesn't need to control them all from the root) that when touched, a prim goes full bright (using whatever color has been set from the first script) and it turns on the point light (controlled by hard set parameters in the script...currently white).  What I'd like is for the point light color to not be set by the script, but rather take its color from the color of the prim.  The intensity I don't mind controlling manually, but not the color.

I'll post both scripts here for you guys to check out.  Maybe there's a way to combine them?  I don't know.  But ultimately, I would the prim and point light to be the same color whenever the prim color is changed by touch.

Here is the "color script":

list grayscale =["black",<0,0,0>,"white",<1,1,1>,"gray",<0.5,0.5,0.5>,"silver",<0.75,0.75,0.75>,"darkgray",<0.4,0.4,0.4>,
    "lightgrey",<0.83,0.83,0.83>];
list reds = ["red",<1,0,0>,"darkred",<0.55,0,0>,"crimson",<0.86,0.08,0.24>,"indianred",<0.8,0.36,0.36>,
    "orangered",<1,0.27,0>];
list pinks = ["hotpink",<1,0.41,0.71>,"pink", <1,0.75,0.8>,"lightpink",<1,0.71,0.76>,"deeppink",<1,0.08,0.58>,
    "fuchsia",<1,0,1>,"orchid",<0.85,0.44,0.84>,"plum",<0.87,0.63,0.87>];
list violets = ["violet",<0.8,0.51,0.8>,"indigo",<0.29,0,0.51>,"lavender",<0.7,0.7,1>,"magenta",<1,0,1>,
    "purple",<0.5,0,0.5>,"darkmagenta",<0.55,0,0.55>,"darkviolet",<0.58,0,0.83>,"blueviolet",<0.54,0.17,0.89>];
list dk_blues = ["darkblue",<0,0,0.55>,"blue",<0,0,1>,"deepskyblue",<0,0.75,1>,"mediumblue",<0,0,0.8>,
    "midnightblue",<0.1,0.1,0.44>,"royalblue",<0.25,0.41,0.88>,"slateblue",<0.42,0.35,0.8>,"steelblue",<0.27,0.51,0.71>];
list lt_blues = ["teal",<0,0.5,0.5>,"turquoise",<0.25,0.88,0.82>,"darkcyan",<0,0.55,0.55>, "lightblue", <0.68,0.85,0.9>,
    "aquamarine",<0.5,1,0.83>,"azure",<0.8,1,1>,"cyan",<0,1,0.9>,"skyblue",<0.53,0.81,0.92>];
list yellows = ["yellow",<1,1,0>,"gold",<1,0.84,0>,"lightyellow",<1,1,0.88>,"goldenrod",<0.85,0.65,0.13>,
    "yellowgreen",<0.6,0.8,0.2>];
list dk_greens = ["darkgreen",<0,0.39,0>,"green",<0,0.5,0>,"forestgreen",<0.13,0.55,0.13>,"lawngreen",<0.49,0.99,0>,
    "springgreen",<0,1,0.5>];
list lt_greens = ["lightgreen",<0.56,0.93,0.56>,"chartreuse",<0.5,1,0>,"greenyellow",<0.68,1,0.18>,"honeydew",<0.94,1,0.94>,
    "limegreen",<0.2,0.8,0.2>,"mintcream",<0.96,1,0.98>,"seagreen",<0.18,0.55,0.34>];
list oranges = ["orange",<1,0.65,0>,"darkorange",<1,0.55,0>,"coral",<1,0.5,0.31>,"navajowhite",<1,0.87,0.68>,
    "salmon",<0.98,0.5,0.45>,"seashell",<1,0.96,0.93>,"brown",<.24,.17,.15>];

//Typically you wouldn't change anything below here, but if you're feelin it, who's gonna stop you?!
//---------------------------------------------------------

integer channel;
integer listen_handle;
key owner;
list sub_menu;
list main_menu = ["grayscale", "reds", "pinks", "violets", "dk_blues", "lt_blues", "yellows", "dk_greens", "lt_greens", "oranges"];


init() {
    llListenRemove(listen_handle);
    owner = llGetOwner();
    channel = llFloor(llFrand(2000000));  //random channel so multiple scripts don't interfere with each other
    listen_handle = llListen(channel, "", owner, "");
}


default
{
    on_rez(integer s) { init(); }
    state_entry() { init(); }
        
    listen(integer channel, string name, key id, string message) {
                        
        if (llListFindList(main_menu, [message]) != -1) {
            if (message == "grayscale") sub_menu = grayscale;
            else if (message == "reds") sub_menu = reds;
            else if (message == "pinks") sub_menu = pinks;
            else if (message == "violets") sub_menu = violets;
            else if (message == "dk_blues") sub_menu = dk_blues;
            else if (message == "lt_blues") sub_menu = lt_blues;
            else if (message == "yellows") sub_menu = yellows;
            else if (message == "dk_greens") sub_menu = dk_greens;
            else if (message == "lt_greens") sub_menu = lt_greens;
            else if (message == "oranges") sub_menu = oranges;
            
            llDialog(owner, "\n\nSelect a color", llList2ListStrided(sub_menu, 0, -1, 2), channel);
            return;  
        }
        
        integer index = llListFindList(sub_menu, [message]);
        if (index != -1) {
            vector color_vector = llList2Vector(sub_menu, index+1);
            if (llGetLinkNumber() == 1) llSetLinkColor(LINK_SET, color_vector, ALL_SIDES);  //If it's root prim, do whole set
            else llSetColor(color_vector, ALL_SIDES);  //otherwise, just do that prim
        }
        
    }   
    
    touch_start(integer s) {
        if (llDetectedKey(0) == owner) {    
            llDialog(owner, "\n\nSelect a color group", main_menu, channel);
        }
    }
}

 

And this is the "full bright/point light script":

default
{
    state_entry()
    {
        llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,FALSE]);
        llSetPrimitiveParams([PRIM_POINT_LIGHT,FALSE,<1, 1, 1>, 1.0, 10.0, 0.75]);
    }
    touch_start(integer total_number)
    {
        llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,TRUE]);
        llSetPrimitiveParams([PRIM_POINT_LIGHT,TRUE,<1, 1, 1>, 1.0, 10.0, 0.75]);
        state off;
    }
}
state off
{
    on_rez(integer start_param)
    {
        llResetScript();
    }
    touch_start(integer total_number)
    {
        state default;
    }
}

 

Thank you all again.  I really appreciate all the help!

Share this post


Link to post
Share on other sites
Posted (edited)

Having no luck...trying again.  I'll try to simplify what I'm looking for.  Below is the script I'm currently using.  What I'd like to know is how (or even if it's possible) to make the PRIM_POINT_LIGHT pull it's color from the prim color on touch (no matter what the color might be at a given time) instead of manually entering the <r,g,b> values for each colored prim.  Thank you!

EDIT:  Also, I've read through and tried many of the functions that MAY apply, but I just don't understand enough to know precisely what they do or where they might belong within the script format to even function properly without syntax errors.

 

On 3/2/2019 at 3:57 PM, LoganNJ1013 said:

default
{
    state_entry()
    {
        llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,FALSE]);
        llSetPrimitiveParams([PRIM_POINT_LIGHT,FALSE,<1, 1, 1>, 1.0, 10.0, 0.75]);
    }
    touch_start(integer total_number)
    {
        llSetPrimitiveParams([PRIM_FULLBRIGHT,ALL_SIDES,TRUE]);
        llSetPrimitiveParams([PRIM_POINT_LIGHT,TRUE,<1, 1, 1>, 1.0, 10.0, 0.75]);
        state off;
    }
}
state off
{
    on_rez(integer start_param)
    {
        llResetScript();
    }
    touch_start(integer total_number)
    {
        state default;
    }
} 

 

Edited by LoganNJ1013

Share this post


Link to post
Share on other sites
Posted (edited)
40 minutes ago, LoganNJ1013 said:

Having no luck...trying again.  I'll try to simplify what I'm looking for.  Below is the script I'm currently using.  What I'd like to know is how (or even if it's possible) to make the PRIM_POINT_LIGHT pull it's color from the prim color on touch (no matter what the color might be at a given time) instead of manually entering the <r,g,b> values for each colored prim.  Thank you!

EDIT:  Also, I've read through and tried many of the functions that MAY apply, but I just don't understand enough to know precisely what they do or where they might belong within the script format to even function properly without syntax errors.

llSetPrimitiveParams has an equivalent llGetPrimitiveParams which does the opposite. Instead of applying a list of parameters, it gives (returns) a list of parameters. (wiki)

 

Reading the wiki page for it is unfortunately not as neat, but if you follow the left-most side of the table (the "Parameter" column), you'll know what to type in for the llGetPrimitveParams list. Since you want to get the prim's color, see:
29b1e6e1ae.png

list params = llGetPrimitiveParams([PRIM_COLOR, 0]);

This gets the color of face 0 (first face). If you use ALL_SIDES instead, you get a bigger list with the colors of each face included. (Probably not needed if all faces are the same color.)

 

So now you have the result stored in a list called "params". The list actually has two values, the color vector and the alpha. To get the color, you can use llList2Vector:

list params = llGetPrimitiveParams([PRIM_COLOR, 0]);
vector color = llList2Vector(params, 0);

Again, this simply returns the first (0) item in the params list as a vector (a thing containing 3 float values).

 

And now you can use the "color" variable for the llSetPrimitiveParams list to re-use that same color.

list params = llGetPrimitiveParams([PRIM_COLOR, 0]);
vector color = llList2Vector(params, 0);
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, color, 1.0, 10.0, 0.75]);

 

P.S. There are some things that are super helpful (even for me) to figure out how stuff works or what it looks like.

llOwnerSay is by far my most used function, I use it a lot whenever I write scripts to make sure I don't make silly mistakes (as often). Everything you give to llOwnersay must be a string, though. You can change a value's type by typecasting it like this:

vector color = llList2Vector(params, 0);
llOwnerSay( (string)color );

And whenever I'm working with lists, I like seeing the entire list. There's a couple ways to do it, like these:

list params = llGetPrimitiveParams([PRIM_COLOR, 0]);

llOwnerSay( llList2CSV(params) );
// looks like: <1.000000, 1.000000, 1.000000>, 1.000000

llOwnerSay( llDumpList2String(params, "|") );
// looks like: <1.000000, 1.000000, 1.000000>|1.000000

 

Edited by Wulfie Reanimator

Share this post


Link to post
Share on other sites
Posted (edited)

@Wulfie Reanimator, that looks great!  And simple!  Thank you!  It's sort of what I was looking at myself, SEEMED to make sense, but I didn't understand HOW they work.  This breakdown makes it a little more understandable and logical.

Now my question is...where does that string of functions belong?  All together, just like that, in the same place as the PRIM_POINT_LIGHT line in the referenced script?  Or do elements of that list belong in other places (like I've seen in other scripts and samples...ie., "list" functions at the top of a script, even before the "state entry")?

EDIT:  Please disregard the above!  I tried it in the same position and it worked!!  I have to click twice to turn it off, then back on, to "reset" the point light to the next chosen color, but it works, so I'm perfectly fine with that!!  Thank you so much!!

Edited by LoganNJ1013

Share this post


Link to post
Share on other sites
Posted (edited)
5 minutes ago, LoganNJ1013 said:

@Wulfie Reanimator, that looks great!  And simple!  Thank you!  It's sort of what I was looking at myself, SEEMED to make sense, but I didn't understand HOW they work.  This breakdown makes it a little more understandable and logical.

Now my question is...where does that string of functions belong?  All together, just like that, in the same place as the PRIM_POINT_LIGHT line in the referenced script?  Or do elements of that list belong in other places (like I've seen in other scripts and samples...ie., "list" functions at the top of a script, even before the "state entry")?

They should all be kept together, but you can put them wherever you want the "light on" to happen.

The other scripts you've seen, where the "stuff" happens before state_entry are either global variables or custom functions. Explaining these in wider context would take a bit of time and should probably be done in a different thread (or you can read the wiki pages on them).

I also added some extra, general tips to my post.

Edited by Wulfie Reanimator

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...