Jump to content
You are about to reply to a thread that has been inactive for 1518 days.

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

Recommended Posts

Posted

Hello! I am trying to make a color picker for a particle system emitted by the wearable object with a lsl RGB message sent via a textbox invoked via HUD. The message will look like <1,1,1>.

How to make the listener recognize this message and set the desired value of RGB? Thanks you for any help! 😍

Here I send message via HUD's textbox:

touch_start(integer num)
{
    if (button == "custom")
    {
        integer channel = -321321;
        gListener = llListen(channel, "", "", "");
        llTextBox(llDetectedKey(0), "Input lsl RGB value e.g. <1,1,1>", channel);
    }
}
          
listen(integer channel, string name, key id, string msg)
{
    llListenRemove(gListener);
    llSay(-123123, msg);
}

And here is particle object listener:

listen(integer channel, string name, key id, string msg)
{
    if (msg == ???) // <---
    {
        RGB = ???; // <---
        partSystem();
    }
}

 

 

Posted (edited)

Take the supp[lied message and cast it to a vector. if the supplied string is not a valid vector (ie has full stops instead of a comma) you'll get a silent conversion to ZERO_VECTOR

colour = (vector) msg;	// sensible to use string trim on this)

if( colour != ZERO_VECTOR) 
{
	// do stuff
}

The thing you'll have to be careful of is extra spaces, <0.5,0.5,0.5> will convert. but <0.5,  0.5,  0.5> will fail because of the spaces after the commas. You will probably end up going through the message copying each non-space character between < and > to a fresh string to guard against such issues

You could also, assuming you might want <0,0,0> as a valid choice, have pre-defined vectors for red,green, blue, yellow,black, white... so the message is tested for these first and if no match, converted to a vector

Edited by Profaitchikenz Haiku
  • Like 1
  • Thanks 1
Posted
32 minutes ago, Profaitchikenz Haiku said:

Take the supp[lied message and cast it to a vector. if the supplied string is not a valid vector (ie has full stops instead of a comma) you'll get a silent conversion to ZERO_VECTOR


colour = (vector) msg;	// sensible to use string trim on this)

if( colour != ZERO_VECTOR) 
{
	// do stuff
}

The thing you'll have to be careful of is extra spaces, <0.5,0.5,0.5> will convert. but <0.5,  0.5,  0.5> will fail because of the spaces after the commas. You will probably end up going through the message copying each non-space character between < and > to a fresh string to guard against such issues

You could also, assuming you might want <0,0,0> as a valid choice, have pre-defined vectors for red,green, blue, yellow,black, white... so the message is tested for these first and if no match, converted to a vector

It works! Thank you so much! :D

            vector colour;
            colour = (vector) msg;    // sensible to use string trim on this
            if ( colour != ZERO_VECTOR) 
            {
                llSetTimerEvent(0);
                RGB = colour;
                partSystem();
            }

 

Posted (edited)
3 hours ago, Tattooshop said:

It works! Thank you so much! :D



            vector colour;
            colour = (vector) msg;    // sensible to use string trim on this
            if ( colour != ZERO_VECTOR) 
            {
                llSetTimerEvent(0);
                RGB = colour;
                partSystem();
            }

 

As Profaitchikenz Haiku mentioned, if black will be a valid option that someone might want to use, then a more complete test could be done...

            // Break up the vector to verify it has the proper number of components
            list v = llParseString2List(llStringTrim(msg, STRING_TRIM), [" "], ["<", ",", ">"]);
            if ( llGetListLength(v) == 7) 
            {
                llSetTimerEvent(0);
                RGB = (vector)llDumpList2String(v, "");
                partSystem();
            }

 

Edited by Phate Shepherd
  • Thanks 1
Posted

A neat trick.

 

Actually what I had in mind was:

list colours = ["red", <--->, "blue", <----> and so on];
  
// then inside the listen event
  
 integer found = llListFindList(colours, [msg]);
  if( found > -1) partColour = llList2vector(colours, found + 1);
  else partColour = (vector) msg;

 

  • Thanks 1
Posted (edited)
6 hours ago, Profaitchikenz Haiku said:

The thing you'll have to be careful of is extra spaces, <0.5,0.5,0.5> will convert. but <0.5,  0.5,  0.5> will fail because of the spaces after the commas. You will probably end up going through the message copying each non-space character between < and > to a fresh string to guard against such issues

The below script will correctly convert a string to a vector:

default
{
    state_entry()
    {
        string color = "<   1,   1,   1   >   ";
        vector v = (vector)color;

        llOwnerSay((string)v);
    }
}

The things that break it are:

  1. Leading space before "<"
  2. Leading space before ","

@Phate Shepherd's example is very good.

Edited by Wulfie Reanimator
  • Thanks 1
You are about to reply to a thread that has been inactive for 1518 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
×
×
  • Create New...