Jump to content

LSL Light Script


VeranniCakes
 Share

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

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

Recommended Posts

Hello, I need help with  this script pls, I'm a beginner but I know a little bit about coding.

I'm trying to turn on a light with a hud, but the light isn't turning on. Here is my code. 

 

//This is the HUD script

//This is a simple Light Hud, turning a Light on and off.

//The light source is on an object called GlowStick, The HUD is called Glowstick HUD

//PRIM_POINT_LIGHT is being used No PRIMGLOW codes

//Channel being used is 100

integer switch;

integer ONButton = 2;

integer OFFButton = 3;

default

{

state_entry()

{

}

touch_start(integer total_number)

{

integer press = llDetectedLinkNumber(0);

if(press == ONButton)

{

llOwnerSay("ON Button");

llRegionSayTo(llGetOwner(),100,"ON Button Connected");

llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <0.2, 0.8, 0.8>, 1.0, 10, 0.75 ]);

}

else if(press == OFFButton)

{

llOwnerSay("OFF Button");

llRegionSayTo(llGetOwner(),100,"OFF Button Connected");

llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <0.2, 0.8, 0.8>, 1.0, 10, 0.75 ]);

}

}

}

_____________________________________________________

//Glowstick Object

default
 {
 
 state_entry()
 {
        llListen(100,"Glow Stick HUD","","");
    }
 
    listen(integer channel, string name, key id, string message)
    {
            if(llGetOwnerKey(id) != llGetOwner() ) return;
  
            else llOwnerSay(message);
      }
 }

Link to comment
Share on other sites

You've sort of got it, you just mixed something up.

In your HUD script, you're correctly using llRegionSayTo, to send a message to your attachments on channel 100.

But then, you're enabling PRIM_POINT_LIGHT in the HUD itself, which won't work since HUDs cannot emit light.

Meanwhile, your glowstick script isn't really doing anything. It's listening to messages and simply repeating them back to you.

 

The glowstick script should check which message it received and enable PRIM_POINT_LIGHT instead of the HUD.

default //Glowstick Object
{
    state_entry()
    {
        llListen(100,"Glow Stick HUD","","");
    }

    listen(integer channel, string name, key id, string message)
    {
        if (llGetOwnerKey(id) != llGetOwner()) return;

        else if (message == "ON Button Connected")
        {
            llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <0.2, 0.8, 0.8>, 1.0, 10, 0.75 ]);
        }
        else if (message == "OFF Button Connected")
        {
            llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <0.2, 0.8, 0.8>, 1.0, 10, 0.75 ]);
        }
    }
}

I think it's also important to point out that you should do your best at keeping the indentation consistent, so you can easily see where the curly-brace pairs are. It's much harder to find mistakes when they're all over the place or not indented at all.

Edited by Wulfie Reanimator
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Both of the llSetPrimitiveParams statements belong in the object that lights up. not in the HUD.  The HUD just sends a message to the light.  The light does the actual lighting.  Just think through the logic.  You've got it mostly right, just in the wrong object.

If you want to be mildly more sophisticated, there are better ways to build a HUD than with separate ON/OFF buttons, but the way you are doing it will work just fine.

 

Hehe ... What Wulfie just said ^^.. He types faster than I do.   😃

Edited by Rolig Loon
  • Like 2
Link to comment
Share on other sites

 

If you want to be mildly more sophisticated, there are better ways to build a HUD than with separate ON/OFF buttons, but the way you are doing it will work just fine.

_________________________________________________________________________________________________________________________________________________________________

 

Yeah It's an easy project,  I'm a beginner. I guess it can pass as sophisticated, thanks lol. 

 

  • Like 1
Link to comment
Share on other sites

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