Jump to content

Flashing Lights Scripting Help Please


Sabastian Zane
 Share

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

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

Recommended Posts

Ok, so I'm quite new to this and need some guidance please.

 

I've created a VU Meter, music volume lights that are meant to go up and down to the music. They don't really scan for music, but randomize a number (simulated volume) and flash according to the randomised number.

Currently I have a controller prim which "Says" the code depending on the number, and then 5 prims that Listen, labeled A, B, C, D & E. 

I am restricted to a 1 second delay, and wondered if there was a way to speed up the lights to a more realistic reaction, but I am also aware that its saying and listening and could cause issues with lag/reaction times etc.

Your assistance would be greatly appreciated. I am new to coding and for the most part piece together parts of coding from one script to another to make it work.. so still learning. 

 

So the controller script is:-

// VU METER

default
{
state_entry()
{
llSetTimerEvent(0.125);
}
timer()
{
integer rand = (integer)llFrand(10);
{
if (rand < 1) {
llSay(-123, "Z");}
else if (rand < 2) {
llSay(-123, "A");}
else if (rand < 4) {
llSay(-123, "B");}
else if (rand < 6) {
llSay(-123, "C");}
else if (rand < 8) {
llSay(-123, "D");}
else if (rand > 7) {
llSay(-123, "E");}
}
}
}

 

And then the Listening Script looks like this (This is for the first Prim - A, which actually lights up on any number as it's the left most piece of the VU Meter and so lights up on ANY sound)

integer light_s = TRUE;
vector lightcolour = <0.0, 1.0, 0.0>;
vector lightcolourdark = <0.0, 0.5, 0.0>;
float intensity = 0.1; // 0-1
float radius = 10.0; // 0-10
float falloff = 0.0; // 0-1
float glow = 0.2;


default
{

state_entry() {
llListen(-123,"", NULL_KEY, "");
}

listen(integer channel, string name, key id, string message) {
if (message == "A") {

// change color!
llSetColor(lightcolour,ALL_SIDES);
llSetPrimitiveParams([
PRIM_POINT_LIGHT, light_s, lightcolour, intensity, radius, falloff,
PRIM_FULLBRIGHT, ALL_SIDES, light_s,
PRIM_GLOW, ALL_SIDES, glow
]);

} else if (message == "Z") {

// change color!
llSetColor(lightcolour,ALL_SIDES);
llSetPrimitiveParams([
PRIM_POINT_LIGHT, FALSE, lightcolourdark, 0, radius, falloff,
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_GLOW, ALL_SIDES, 0
]);

} else if (message == "B") {

// change color!
llSetColor(lightcolour,ALL_SIDES);
llSetPrimitiveParams([
PRIM_POINT_LIGHT, light_s, lightcolour, intensity, radius, falloff,
PRIM_FULLBRIGHT, ALL_SIDES, light_s,
PRIM_GLOW, ALL_SIDES, glow
]);

} else if (message == "C") {

// change color!
llSetColor(lightcolour,ALL_SIDES);
llSetPrimitiveParams([
PRIM_POINT_LIGHT, light_s, lightcolour, intensity, radius, falloff,
PRIM_FULLBRIGHT, ALL_SIDES, light_s,
PRIM_GLOW, ALL_SIDES, glow
]);

} else if (message == "D") {

// change color!
llSetColor(lightcolour,ALL_SIDES);
llSetPrimitiveParams([
PRIM_POINT_LIGHT, light_s, lightcolour, intensity, radius, falloff,
PRIM_FULLBRIGHT, ALL_SIDES, light_s,
PRIM_GLOW, ALL_SIDES, glow
]);
} else if (message == "E") {

// change color!
llSetColor(lightcolour,ALL_SIDES);
llSetPrimitiveParams([
PRIM_POINT_LIGHT, light_s, lightcolour, intensity, radius, falloff,
PRIM_FULLBRIGHT, ALL_SIDES, light_s,
PRIM_GLOW, ALL_SIDES, glow
]);

}
}

}

 

 

Many thanks in advance.


Sab

 

Link to comment
Share on other sites

If these lights are all within linking distance (54m radius), then you'll be far better off linking them together and using llSetLinkPrimitiveParamsFast() to control all their properties from a single script.

Note that you can update all the prims from a single function call, using PRIM_LINK_TARGET to step through the individual links. (That's a win because it bundles the changes into fewer update packets to the viewer.)

To keep your sanity, you'll want to populate a little list of the link numbers corresponding to each of the named prims; then you can reference the linked prims from the values stored in the list.

Also, is it important that the point lights -- the actual emissive light sources -- accurately track the flashing lights like this? It maybe central to the experience if these are really big objects, which is fine, but if not: Changing light sources contributes a lot of rendering lag. It's no big deal to the script and the sim, but viewers with advanced lighting enabled -- well, even those with out it -- will have a lot more work to do if the "blinkenlights" are that realistic.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

script commands for setting prim parameters like glow, and light status, both single prim and linkset versions, have that built in 0.2 second delay per command so 5 lights 1 second delay...

 

However there are FAST versions of these commands that do not have this delay, 

Be aware that there is no guarantee that parameters set with the 'fast' versions will actually happen in the same order that your script sends the commands, and some scripts thus put a manually coded delay between multiple commands using the llSleep function so you could put in some very small delay between toggling the state of each prim say 0.05 seconds to try and ensure they turn on and off in the right order.

 

Also. unless the 5 lights are massive spotlights/floodlights etc, you might not want to put 5 sl light sorces in an actual object.

 

typically opengl used to only support 8 light sources, sl reserves 2 of these for the  sim sun and sim moon... leaving only 6 that can be displayed, having 5 on the object is therefore possible, but viewers tend to only display the closest 6 to the clients avatar location, so they see their 2 or 3 facelights (ewww) and then only see some of your lights anyway.

 

If you are using advanced lighting and say a directional light, making the light object rectangular and using a "5 light texture" with a small resolution, and simply changing the  light texture for a different one, would need fewer parameter setting commands and use less actual lifght sources, and better handle the lighting change, say a rectangular texture with a black background and 1 to 5 colored circles on it.

 

Swappng from the 1 circle lit texture to the 2 circle lit texture is a single script command, and simulates 2 light sources quite nicely

 

  • Thanks 1
Link to comment
Share on other sites

Thanks for your help. Yep Linked Prims worked, thanks for that Qie Niangao

It might look a bit messy, but I managed to reduce the whole object from 11 scripts to this single script, and NO MORE SAYING AND LISTENING !! YAY!! 

And I know I might have found another method to make them light up, but having them light up in this order makes it look more realistic, as can be seen here :-

 

https://gyazo.com/fd9d7c33094b4d0031aa538cdc1cd8b3

Script is as follows:-

 

// VU METER - Sabastian Zane

default
{
state_entry()
{
llSetTimerEvent(0.125);
}
timer()
{
integer rand = (integer)llFrand(10);
{
if (rand < 1)
{
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_FULLBRIGHT, ALL_SIDES, FALSE
]);
}
else if (rand < 2)
{
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_LINK_TARGET,11,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,2,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
}
else if (rand < 4)
{
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_LINK_TARGET,11,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,2,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,10,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,3,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
}
else if (rand < 6)
{
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_LINK_TARGET,11,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,2,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,10,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,3,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,9,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,4,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
}
else if (rand < 8)
{
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_LINK_TARGET,11,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,2,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,10,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,3,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,9,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,4,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,8,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,5,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
}
else if (rand > 7)
{
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_FULLBRIGHT, ALL_SIDES, FALSE,
PRIM_LINK_TARGET,11,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,2,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,10,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,3,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,9,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,4,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,8,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,5,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,7,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
llSetLinkPrimitiveParamsFast(LINK_SET, [
PRIM_LINK_TARGET,6,
PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_GLOW, ALL_SIDES,0.2
]);
}
}
}
}

 

 

 

Link to comment
Share on other sites

Congratulations.  I'm glad it worked.

For future reference, the whole point of using PRIM_LINK_TARGET is to combine several calls to llSetLinkPrimitiveParamsFast into a single one. That's especially helpful if you have a re4peated set of parameters.  So, for example, instead of writing

llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_FULLBRIGHT, ALL_SIDES, FALSE,PRIM_LINK_TARGET,11,PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,PRIM_FULLBRIGHT, ALL_SIDES, TRUE,PRIM_GLOW, ALL_SIDES,0.2]);llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_LINK_TARGET,2,PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,PRIM_FULLBRIGHT, ALL_SIDES, TRUE,PRIM_GLOW, ALL_SIDES,0.2]);llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_LINK_TARGET,10,PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,PRIM_FULLBRIGHT, ALL_SIDES, TRUE,PRIM_GLOW, ALL_SIDES,0.2]);llSetLinkPrimitiveParamsFast(LINK_SET, [PRIM_LINK_TARGET,3,PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0,PRIM_FULLBRIGHT, ALL_SIDES, TRUE,PRIM_GLOW, ALL_SIDES,0.2]);

you can write

 

list lParams = [PRIM_POINT_LIGHT, TRUE, <0.0,1.0,0.0>,0.1,10,0.0, PRIM_FULLBRIGHT, ALL_SIDES, 
TRUE,PRIM_GLOW, ALL_SIDES,0.2];llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_FULLBRIGHT, ALL_SIDES, FALSE,34,11]
+ lParams + [34,2] + lParams + [34,10] + lParams + [34,3] + lParams);

where 34 is the integer equivalent of PRIM_LINK_TARGET.  Not only does it save you a lot of typing (and -- in my case -- the chance of making a boatload of typos), it makes your script more readable and actually a bit faster.  :smileywink:

 

  • Thanks 2
Link to comment
Share on other sites

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