Jump to content

HUD & Listener Help


Recommended Posts

I've been doing pretty ok with basic scripting, but ran into an issue I can't seem to figure out. I have a HUD script and listener script (placed in a piece of jewelry). Trying to get the HUD to change only the tint and vector color when each box is clicked. Zero idea where I'm going wrong. Any help would be greatly appreciated.

HUD script:

integer chan = 15113234731;

// ------------------------------------------------------------------------------ Face All_Sides :: Metal

//      Gold
string clrgld = "gold";

//      Rose Gold
string clrrgld = "rose gold";

//      Silver
string clrslvr = "silver";

//      Gunmetal
string clrgnmtl = "gunmetal";

// ===============================================================================================================

default
{ 
    changed(integer change)
    {
        if (change & CHANGED_OWNER) // Makes sure it's changing the CURRENT OWNER's object, rather than previous owner
        {
            llOwnerSay("Script owner changed; resetting");
            llResetScript();
        }
    }
    
    state_entry()
    {
        llListen(chan,"",llGetOwner(),"");
    }
    
    touch_start(integer total_number)
    {
    // Options for All_Sides :: Metal
        if (llGetLinkName(llDetectedLinkNumber(5)) == "gold")
        {
            llRegionSay(chan,clrgld);
        }
        
         if (llGetLinkName(llDetectedLinkNumber(4)) == "rose gold")
        {
            llRegionSay(chan,clrrgld);
        }
        
         if (llGetLinkName(llDetectedLinkNumber(3)) == "silver")
        {
            llRegionSay(chan,clrslvr);
        } 
        
        if (llGetLinkName(llDetectedLinkNumber(2)) == "gunmetal")
        {
            llRegionSay(chan,clrgnmtl);
        }
    }
}

 

Listener script:

integer chan = 15113234731;

// ==================

default
{
    state_entry()
    {
        llListen(chan,"",NULL_KEY,"");
    }

        listen(integer channel, string name, key id, string msg)
    
    {
        if(msg == "gold")
        {
            llSetColor(<226,201,111>, ALL_SIDES);
            llSetPrimitiveParams([ PRIM_SPECULAR, ALL_SIDES, "85b41f09-515a-0886-7c50-a8675d5e60af", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0, <1.0, 1.0, 0.0> , 75, 0]);
        }

        if(msg == "rose gold")
        {
            llSetColor(<240,158,111>, ALL_SIDES);
            llSetPrimitiveParams([ PRIM_SPECULAR, ALL_SIDES, "85b41f09-515a-0886-7c50-a8675d5e60af", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0, <1.0, 0.502, 0.0> , 75, 0]);
        }
        
        if(msg == "silver")
        {
            llSetColor(<168,168,168>, ALL_SIDES);
            llSetPrimitiveParams([ PRIM_SPECULAR, ALL_SIDES, "85b41f09-515a-0886-7c50-a8675d5e60af", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0, <1.0, 1.0, 1.0> , 75, 0]);
        }
        
        if(msg == "gunmetal")
        {
            llSetColor(<67,67,67>, ALL_SIDES);
            llSetPrimitiveParams([ PRIM_SPECULAR, ALL_SIDES, "85b41f09-515a-0886-7c50-a8675d5e60af", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0, <0.502, 0.502, 0.502> , 75, 0]);
        }
    }
}

 

Link to comment
Share on other sites

The correct format for llSetLinkPrimitiveParams is llSetLinkPrimitiveParams( integer link, list rules );  You've left off the first parameter in  each case, so the link isn't identified.  By the way, unless there's a good reason to, it's usually best to use  llSetLinkPrimitiveParamsFast instead.  ;)

Edited by Rolig Loon
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Rolig Loon said:

The correct format for llSetLinkPrimitiveParams is llSetLinkPrimitiveParams( integer link, list rules );

The script in the OP compiles, llSetPrimitiveParams() without 'link' or 'fast' is a valid function, albeit an outdated one that probably ought not be used.

The main problem I see is in the lines that look like:

if (llGetLinkName(llDetectedLinkNumber(5)) == "gold")

In the context of a HUD, 0 is the only sensible argument to llDetectedLinkNumber, because you can't have more than one person simultaneously touch a HUD. It'd also be better to store the value of the function rather than calling it for each conditional, or even better to restructure in a way that doesn't use repeated conditionals:

(removed identical events to reduce spam)

// HUD
integer chan = 15113234731;
list colors = 
[   "gold", "rose gold", "silver", "gunmetal" // no final ','
];

default
{    
    touch_start(integer total_number)
    {
        string name = llGetLinkName(llDetectedLinkNumber(0));
        
        if(-1!=llListFindList(colors,[name]))
        {   //the button touched was a color name, send to attachment: 
            // if the object is an attachment that is attached, can be more efficient:
            llRegionSayTo(llGetOwner(),chan,name);
            //llRegionSay(chan,name);
        }
    }
}

you can also do similar in the listener using either linkset data or a strided list to associate the name of the color with its color and specular values.

  • Like 2
Link to comment
Share on other sites

So I've gotten the HUD to work and added a couple LlOwnerSay messages in there to make sure the correct msg is being processed. But the prim color and vector color are just not processing and I'm not sure why. This is the latest listener script:

integer chan = 15113234731;

// ==================

default
{
    state_entry()
    {
        llListen(chan,"",NULL_KEY,"");
    }

        listen(integer channel, string name, key id, string msg)
    
    {
        llOwnerSay(msg);

        if(msg == "gold")
        {
            llOwnerSay(msg + " if statement has been processed.");

            llSetColor(<226,201,111>, ALL_SIDES);
            llSetPrimitiveParams([PRIM_SPECULAR, ALL_SIDES, "85b41f09-515a-0886-7c50-a8675d5e60af", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0, <1.0, 1.0, 0.0> , 75, 0]);
        }

        if(msg == "rose gold")
        {
            llOwnerSay(msg + " if statement has been processed.");

            llSetColor(<240,158,111>, ALL_SIDES);
            llSetPrimitiveParams([PRIM_SPECULAR, ALL_SIDES, "85b41f09-515a-0886-7c50-a8675d5e60af", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0, <1.0, 0.502, 0.0> , 75, 0]);
        }
        
        if(msg == "silver")
        {
            llOwnerSay(msg + " if statement has been processed.");

            llSetColor(<168,168,168>, ALL_SIDES);
            llSetPrimitiveParams([PRIM_SPECULAR, ALL_SIDES, "85b41f09-515a-0886-7c50-a8675d5e60af", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0, <1.0, 1.0, 1.0> , 75, 0]);
        }
        
        if(msg == "gunmetal")
        {
            llOwnerSay(msg + " if statement has been processed.");

            llSetColor(<67,67,67>, ALL_SIDES);
            llSetPrimitiveParams([PRIM_SPECULAR, ALL_SIDES, "85b41f09-515a-0886-7c50-a8675d5e60af", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0, <0.502, 0.502, 0.502> , 75, 0]);
        }
    }
}

 

Link to comment
Share on other sites

Colors in LSL are in range 0.0-1.0, not 0-255 like "everyday" RGB. Trying to set your color to <67, 67, 67> for instance gets capped to <1, 1, 1> which is white.

The easy way is to divide your existing vectors by 255 to bring them into the 0.0-1.0 range, e.g. llSetColor(<67, 67, 67>/255, ALL_SIDES).

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

6 hours ago, Frionil Fang said:

Colors in LSL are in range 0.0-1.0, not 0-255 like "everyday" RGB. Trying to set your color to <67, 67, 67> for instance gets capped to <1, 1, 1> which is white.

The easy way is to divide your existing vectors by 255 to bring them into the 0.0-1.0 range, e.g. llSetColor(<67, 67, 67>/255, ALL_SIDES).

So I used LSL color in the vector color place where the wiki shows to, but I def misread the wiki for SetColor. Been staring at this for days now and just glazed right over. Thank you so much! It's alive!!

Link to comment
Share on other sites

the Object script can follow the same style as the HUD script example that Tessa showed

longhand example
 

integer chan = 15113234731;

// strided list where color vectors are adjacent to the user-defined name
list colors = [
// name,       color
  "gold",      <226,201,111>,
  "rose gold", <240, 158, 111>,
  "silver",    <168, 168,168>,
  "gunmetal",  <67,67,67>
];

default
{   
    state_entry()
    {
       // listen only for owner
       llListen(chan, "", llGetOwner(), "");
    }

    changed(integer change)
    {
       if (change & CHANGED_OWNER)
          llResetScript();
    }

    listen (integer channel, string name, key id, string msg)
    {
        // look up colors list to get index of msg
        integer index = llListFindList(colors, [msg]);

        if (~index)  // msg found
        {
           // color vector is at index + 1
           vector color = llList2Vector(colors, index + 1) / 255;

           llSetColor(color, ALL_SIDES);
        }
    }
}

 

Edited by elleevelyn
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...