Jump to content

Get something from a list via msg?


Prinavu
 Share

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

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

Recommended Posts

Ok so with some help from this forum i managed to wip something up to make a specular color applier, but now I am stuck on how to fetch a  vector color corresponding to the msg received in the listener from my list?

I highlighted the area in the script below.

 

vector violet = <1, 1, 0.5>;
list colorsList = [<0.00,0.00,0.00>,<1, 1, 0.5>];

setGlossColor(vector color) //Function
{
    integer face;
    list params = llGetLinkPrimitiveParams(LINK_THIS,[PRIM_SPECULAR, face]);
//  [string texture, vector repeats, vector offsets, float rotation_in_radians, vector color, integer glossiness, integer environment]
    string texture = llList2String(params,0);
    vector repeats = llList2Vector(params,1);
    vector offsets = llList2Vector(params,2);
    float rotation_in_radians = llList2Float(params,3);
    vector color = llList2Vector(params,4);
    integer glossiness = llList2Integer(params,5);
    integer environment = llList2Integer(params,6);
    
    
    
    llSetLinkPrimitiveParamsFast(LINK_THIS,
    [
    PRIM_SPECULAR, ALL_SIDES, texture, repeats, offsets,rotation_in_radians, <How do i fetch a  vector color corresponding the msg received in the listener from my list?> , glossiness,environment     
    ]);
}

default
{
    state_entry(){llListen(83458,"",NULL_KEY,"");}
    
    
    listen(integer channel, string name, key id, string msg)
    { 
        if (llGetOwner() == llGetOwnerKey(id))
         
         if (msg == "Violet")
         { 
           setGlossColor(<1, 1, 0.5>);
          }
          else if (msg == "Test")
          {
              
         }
    }
}

Edited by Prinavu
Link to comment
Share on other sites

Without complicating it with the usage of strided lists, just as an example... Try to put this in the listen event instead of the ifs.

integer pos = llListFindList(colorsNames, (list)msg);
if (~pos)
{
   setGlossColor(llList2Vector(colorsList, pos));
}

And add this at the top.

list colorsNames = ["Black", "Violet"];
  • Like 1
Link to comment
Share on other sites

1 minute ago, panterapolnocy said:

Without complicating it with the usage of strided lists, just as an example... Try to put this in the listen event instead of the ifs.

integer pos = llListFindList(colorsNames, (list)msg);
if (~pos)
{
   setGlossColor(llList2Vector(colorsList, pos));
}

And add this at the top.

list colorsNames = ["Black", "Violet"];

I can't wait to know all this simple stuff, thank you so much! Will try it now ❤️

Link to comment
Share on other sites

37 minutes ago, panterapolnocy said:

Without complicating it with the usage of strided lists, just as an example... Try to put this in the listen event instead of the ifs.

integer pos = llListFindList(colorsNames, (list)msg);
if (~pos)
{
   setGlossColor(llList2Vector(colorsList, pos));
}

And add this at the top.

list colorsNames = ["Black", "Violet"];

 

 

It doesn't work, but I think it's because I need to enter a value where the vector is in the   llSetLinkPrimitiveParamsFast for the color, I don't know what i should enter thought 

llSetLinkPrimitiveParamsFast(LINK_THIS,
    [
    PRIM_SPECULAR, ALL_SIDES, texture, repeats, offsets,rotation_in_radians,    <0,0,0> HERE  , glossiness,environment     
    ]);

 

 

Edited by Prinavu
Link to comment
Share on other sites

Because I'm weird, I actually like using JSON for this, for example:

string ColoursJson = "{\"black\":\"<0,0,0>\",\"white\":\"<1,1,1>\",\"violet\":\"<1,1,0.5>\"}"; //Colours in JSON format (key:value), with the key being the colour's name and value being the LSL colour.

You can then use the following for you llSetLinkPrimitiveParamsFast

string ColourVal = llJsonGetValue(ColoursJson,[llToLower(msg)]); //converts msg to lower case, then tries to search for it in the Json
if(ColourVal != JSON_INVALID) //if the colour was found in the Json
{
	llSetLinkPrimitiveParamsFast(LINK_THIS,
    	[
    	PRIM_SPECULAR, ALL_SIDES, texture, repeats, offsets,rotation_in_radians, (vector)llJsonGetValue(ColoursJson,[llToLower(msg)]) , glossiness,environment     
    	]);
}
else
{
	llSay(0, "I don't know that colour, " + msg + "!"); //colour wasn't found in the Json
}

 

  • Like 1
Link to comment
Share on other sites

9 hours ago, Prinavu said:

Ok so with some help from this forum i managed to wip something up to make a specular color applier, but now I am stuck on how to fetch a  vector color corresponding to the msg received in the listener from my list?

There are multiple ways of doing it. Because lists in LSL are heterogenous (meaning that they can store values of multiple types simultaneously) you can take advantage of it and you can do it by using only one list.

Simple example:

list colors = ["Red", <1,0,0>, "Green", <0,1,0>, "Blue", <0,0,1>];

setGlossColor(string colorName)
{
    // ... your code ...
    
    integer pos;

    if ((pos = llListFindList(colors, [colorName])) >= 0)
    {
        // we found the color
        vector color = llList2Vector(colors, pos+1);
        llSay(0, colorName + " = " + (string)color);
    }
    else {
        llSay(0, "color '" + colorName + "' not found");
    }
    
    // ... your code ...
}

default
{
    state_entry()
    {
        llListen(83458, "", NULL_KEY, "");
    }
    
    listen(integer channel, string name, key id, string msg)
    { 
        if (llGetOwner() == llGetOwnerKey(id))
        {    
            setGlossColor(msg);
        }
    }
}

As llListFindList according to wiki strictly checks types, you don't have to worry about an implicit typecast and getting a wrong value.

Just be careful to keep the pattern in the colors list (color1Name, color1Value, color2Name, color2Value, ...).

Edited by tomm55
grammar :)
  • Like 1
Link to comment
Share on other sites

On 1/31/2022 at 11:16 AM, Prinavu said:

It doesn't work, but I think it's because I need to enter a value where the vector is in the   llSetLinkPrimitiveParamsFast for the color, I don't know what i should enter thought 

Replace this:

setGlossColor(vector color) //Function

With this:

setGlossColor(vector theColor) //Function

And then in your function use "theColor" in your llSetLinkPrimitiveParamsFast().

  • Like 1
Link to comment
Share on other sites

32 minutes ago, panterapolnocy said:

Replace this:

setGlossColor(vector color) //Function

With this:

setGlossColor(vector theColor) //Function

And then in your function use "theColor" in your llSetLinkPrimitiveParamsFast().

Thank you! Sorry they held my comments for moderation. Thank you all again for the help ❤️

Link to comment
Share on other sites

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