Tattooshop Posted October 8, 2020 Posted October 8, 2020 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(); } }
Profaitchikenz Haiku Posted October 8, 2020 Posted October 8, 2020 (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 October 8, 2020 by Profaitchikenz Haiku 1 1
Tattooshop Posted October 8, 2020 Author Posted October 8, 2020 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! vector colour; colour = (vector) msg; // sensible to use string trim on this if ( colour != ZERO_VECTOR) { llSetTimerEvent(0); RGB = colour; partSystem(); }
Phate Shepherd Posted October 8, 2020 Posted October 8, 2020 (edited) 3 hours ago, Tattooshop said: It works! Thank you so much! 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 October 8, 2020 by Phate Shepherd 1
Profaitchikenz Haiku Posted October 8, 2020 Posted October 8, 2020 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; 1
Wulfie Reanimator Posted October 8, 2020 Posted October 8, 2020 (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: Leading space before "<" Leading space before "," @Phate Shepherd's example is very good. Edited October 8, 2020 by Wulfie Reanimator 1
Recommended Posts
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