Tattooshop Posted November 1, 2020 Share Posted November 1, 2020 Hello! I'm trying to create a lighting script with a light color preset menu and one button for a custom RGB value through a textbox. Therefore, when you click on this button, a text box should appear. but it doesn't work. the problem is I can't figure out where to insert the llTextBox and which channel to use if the menu and the have different channels? Thanks in advance for any help! // Short version just to display what I mean vector RED_COLOR = <1.000, 0.000, 0.000>; // Light color vector lsl RGB vector GREEN_COLOR = <0.000, 1.000, 0.000>; vector WHITE_COLOR = <1.000, 1.000, 1.000>; vector CUSTOM_COLOR; float INTENSITY = 1.0; float RADIUS = 10.0; float FALLOFF = 0.0; float GLOW = 1.0; integer LIGHT_PRIM = LINK_THIS; integer LIGHT_FACE = ALL_SIDES; list MENU_MAIN = ["RED","GREEN","CUSTOM","OFF"]; integer menu_handler; integer menu_channel; menu(key user,string title,list buttons) { llListenRemove(menu_handler); menu_channel = (integer)(llFrand(99999.0) * -1); menu_handler = llListen(menu_channel,"","",""); llDialog(user,title,buttons,menu_channel); llSetTimerEvent(30.0); } default { state_entry() { } touch_start(integer total_number) { menu(llDetectedKey(0), "\nText for Menu.", MENU_MAIN); } listen(integer channel,string name,key id,string message) { if (channel == menu_channel) { llListenRemove(menu_handler); llSetTimerEvent(0); if (message == "RED") { llSay(0, "Red Light"); llSetLinkPrimitiveParamsFast(LIGHT_PRIM, [PRIM_GLOW, LIGHT_FACE, GLOW, PRIM_COLOR, LIGHT_FACE, RED_COLOR, 1.0, PRIM_POINT_LIGHT, TRUE, RED_COLOR , INTENSITY , RADIUS , FALLOFF ]); } else if (message == "GREEN") { llSay(0, "Green Light"); llSetLinkPrimitiveParamsFast(LIGHT_PRIM, [PRIM_GLOW, LIGHT_FACE, GLOW, PRIM_COLOR, LIGHT_FACE, GREEN_COLOR, 1.0, PRIM_POINT_LIGHT, TRUE, GREEN_COLOR , INTENSITY , RADIUS , FALLOFF ]); } else if (message == "CUSTOM") <<< { vector color; color = (vector) message; llTextBox(llDetectedKey(0), "Type your RGB below", channel); if ( color != ZERO_VECTOR) CUSTOM_COLOR = color; llSay(0, "Custom Light"); llSetLinkPrimitiveParamsFast(LIGHT_PRIM, [PRIM_GLOW, LIGHT_FACE, GLOW, PRIM_COLOR, LIGHT_FACE, CUSTOM_COLOR, 1.0, PRIM_POINT_LIGHT, TRUE, CUSTOM_COLOR , INTENSITY , RADIUS , FALLOFF ]); } else if (message == "OFF") { llSay(0, "Light is OFF"); llSetLinkPrimitiveParamsFast(LIGHT_PRIM, [PRIM_GLOW, LIGHT_FACE, FALSE, PRIM_COLOR, LIGHT_FACE, WHITE_COLOR, 1.0, PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR // COLOR , 0.0 // INTENSITY , 0.0 // RADIUS , 2.0 // FALLOFF ]); } } } timer() { llListenRemove(menu_handler); llSetTimerEvent(0); } } Link to comment Share on other sites More sharing options...
Qie Niangao Posted November 1, 2020 Share Posted November 1, 2020 A hint: In the "CUSTOM" case, you'll pop up the textbox, but you won't be able to set the color right away; instead, you'll get another listen() event with the user's textbox response (if any) to parse and use as the color vector. You can use the same or a different channel; either way you'll need to recognize that this new listen() event is your textbox response, and to timeout both dialogs and textboxes. 1 Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted November 1, 2020 Share Posted November 1, 2020 56 minutes ago, Qie Niangao said: A hint: In the "CUSTOM" case, you'll pop up the textbox, but you won't be able to set the color right away; instead, you'll get another listen() event with the user's textbox response (if any) to parse and use as the color vector. You can use the same or a different channel; either way you'll need to recognize that this new listen() event is your textbox response, and to timeout both dialogs and textboxes. Another hint: Don't try literally adding another "timer() { }" into the script. 1 Link to comment Share on other sites More sharing options...
Tattooshop Posted November 1, 2020 Author Share Posted November 1, 2020 1 hour ago, Qie Niangao said: A hint: In the "CUSTOM" case, you'll pop up the textbox, but you won't be able to set the color right away; instead, you'll get another listen() event with the user's textbox response (if any) to parse and use as the color vector. You can use the same or a different channel; either way you'll need to recognize that this new listen() event is your textbox response, and to timeout both dialogs and textboxes. 14 minutes ago, Wulfie Reanimator said: Another hint: Don't try literally adding another "timer() { }" into the script. Thanks a lot for your responses! I'm not sure if I understood everything correctly, I decided that I needed to add a second listen event, and I get an error "name previously..." about string message. What am I doing wrong? listen(integer channel, string name, key id, string message) { if (message == "CUSTOM") { llListenRemove(gListener); vector color; color = (vector) message; llTextBox(llDetectedKey(0), "Input lsl RGB value e.g. <1.0,1.0,1.0>", menu_handler); if ( color != ZERO_VECTOR) CUSTOM_COLOR = color; llSay(0, "Custom Light"); llSetLinkPrimitiveParamsFast(LIGHT_PRIM, [PRIM_GLOW, LIGHT_FACE, GLOW, PRIM_COLOR, LIGHT_FACE, CUSTOM_COLOR, 1.0, PRIM_POINT_LIGHT, TRUE, CUSTOM_COLOR , INTENSITY , RADIUS , FALLOFF ]); } Link to comment Share on other sites More sharing options...
Phate Shepherd Posted November 1, 2020 Share Posted November 1, 2020 Although very unlikely, your channel calculation could pick channel 0... which you might want to avoid. 1 Link to comment Share on other sites More sharing options...
Qie Niangao Posted November 1, 2020 Share Posted November 1, 2020 9 minutes ago, Tattooshop said: Thanks a lot for your responses! I'm not sure if I understood everything correctly, I decided that I needed to add a second listen event, and I get an error "name previously..." about string message. Ah, I think I see the confusion. You don't want another listen event handler -- you do only get one of those per script state -- but that one handler will be presented with another event. So first the script gets an event with "CUSTOM" in the message and the handler issues an llTextBox(), but it won't get the response from that textbox until another event comes into your listen handler. It won't say "CUSTOM" but rather it'll just be the text of whatever the user types into your textbox. 1 Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted November 2, 2020 Share Posted November 2, 2020 13 hours ago, Tattooshop said: Thanks a lot for your responses! I'm not sure if I understood everything correctly, I decided that I needed to add a second listen event, and I get an error "name previously..." about string message. What am I doing wrong? Add another llListen to open a listener on some other channel. Whenever you need a textbox, use that second channel for it. This way, you can do: listen(integer channel, string name, key id, string message) { if (channel == menu_channel) { // menu stuff } else if (channel == textbox_channel) { // textbox stuff } } 1 Link to comment Share on other sites More sharing options...
Xiija Posted November 2, 2020 Share Posted November 2, 2020 (edited) so, with Phate & Wulfies suggestions, your channel setup might be something like... llListenRemove( menu_handler ); llListenRemove( textbox_handler ); menu_channel = 0x80000000 | (integer)("0x"+(string)llGetKey() ) * -1; textbox_channel = menu_chan + 100; menu_handler = llListen(menu_channel,"","",""); textbox_handler = llListen(textbox_channel,"","",""); Edited November 2, 2020 by Xiija 1 Link to comment Share on other sites More sharing options...
Tattooshop Posted November 2, 2020 Author Share Posted November 2, 2020 (edited) Thank you so much! Here is what I got but it still refuses to response on "CUSTOM" button // Short version integer gListener; vector RED_COLOR = < 1.000, 0.000, 0.000 > ; // Light color vector lsl RGB vector CUSTOM_COLOR; float INTENSITY = 1.0; float RADIUS = 10.0; float FALLOFF = 0.0; float GLOW = 1.0; integer LIGHT_PRIM = LINK_THIS; //LINK_SET or prim number integer LIGHT_FACE = ALL_SIDES; //light face list MENU_MAIN = ["RED", "OFF", "CUSTOM"]; integer menu_handler; integer menu_channel; integer textbox_handler; integer textbox_channel; menu(key user, string title, list buttons) { llListenRemove(menu_handler); llListenRemove(textbox_handler); menu_channel = 0x80000000 | (integer)("0x" + (string) llGetKey()) * -1; textbox_channel = menu_channel + 100; menu_handler = llListen(menu_channel, "", "", ""); textbox_handler = llListen(textbox_channel, "", "", ""); llDialog(user, title, buttons, menu_channel); llSetTimerEvent(30.0); } default { state_entry() { } touch_start(integer total_number) { menu(llDetectedKey(0), "\nText for Menu.", MENU_MAIN); } listen(integer channel, string name, key id, string message) { if (channel == menu_channel) { llListenRemove(menu_handler); llSetTimerEvent(0); if (message == "RED") { llSay(0, "Red Light"); llSetLinkPrimitiveParamsFast(LIGHT_PRIM, [PRIM_GLOW, LIGHT_FACE, GLOW, PRIM_COLOR, LIGHT_FACE, RED_COLOR, 1.0, PRIM_POINT_LIGHT, TRUE, RED_COLOR, INTENSITY, RADIUS, FALLOFF ]); } else if (message == "OFF") { llSay(0, "Light is OFF"); llSetLinkPrimitiveParamsFast(LIGHT_PRIM, [PRIM_GLOW, LIGHT_FACE, FALSE, PRIM_COLOR, LIGHT_FACE, WHITE_COLOR, 1.0, PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR // COLOR , 0.0 // INTENSITY , 0.0 // RADIUS , 2.0 // FALLOFF ]); } } else if (channel == textbox_channel) { llListenRemove(textbox_handler); if (message == "CUSTOM") { vector color; color = (vector) message; llTextBox(llDetectedKey(0), "Input lsl RGB value e.g. <1.0,1.0,1.0>", textbox_handler); if (color != ZERO_VECTOR) { CUSTOM_COLOR = color; llSay(0, "Custom Light"); llSetLinkPrimitiveParamsFast(LIGHT_PRIM, [PRIM_GLOW, LIGHT_FACE, GLOW, PRIM_COLOR, LIGHT_FACE, CUSTOM_COLOR, 1.0, PRIM_POINT_LIGHT, TRUE, CUSTOM_COLOR, INTENSITY, RADIUS, FALLOFF ]); } } } } timer() { llListenRemove(menu_handler); llListenRemove(textbox_handler); llSetTimerEvent(0); } } Edited November 2, 2020 by Tattooshop Link to comment Share on other sites More sharing options...
Tattooshop Posted November 2, 2020 Author Share Posted November 2, 2020 6 hours ago, Wulfie Reanimator said: Add another llListen to open a listener on some other channel. Whenever you need a textbox, use that second channel for it. This way, you can do: listen(integer channel, string name, key id, string message) { if (channel == menu_channel) { // menu stuff } else if (channel == textbox_channel) { // textbox stuff } } 1 hour ago, Xiija said: so, with Phate & Wulfies suggestions, your channel setup might be something like... llListenRemove( menu_handler ); llListenRemove( textbox_handler ); menu_channel = 0x80000000 | (integer)("0x"+(string)llGetKey() ) * -1; textbox_channel = menu_chan + 100; menu_handler = llListen(menu_channel,"","",""); textbox_handler = llListen(textbox_channel,"","",""); 19 hours ago, Qie Niangao said: Ah, I think I see the confusion. You don't want another listen event handler -- you do only get one of those per script state -- but that one handler will be presented with another event. So first the script gets an event with "CUSTOM" in the message and the handler issues an llTextBox(), but it won't get the response from that textbox until another event comes into your listen handler. It won't say "CUSTOM" but rather it'll just be the text of whatever the user types into your textbox. Link to comment Share on other sites More sharing options...
KT Kingsley Posted November 2, 2020 Share Posted November 2, 2020 (edited) The message "CUSTOM" goes out on menu_channel – it's one of the menu buttons sent by the menu – so you should check for it in the if (channel == menu_channel) section of the listen event and open the text box from there. The if (channel == textbox_channel) section of the listen event should only be processing the message sent by the text box. Edited November 2, 2020 by KT Kingsley 1 Link to comment Share on other sites More sharing options...
Qie Niangao Posted November 2, 2020 Share Posted November 2, 2020 (edited) Going with two distinct listener channels is a fine choice, but the menu items including "CUSTOM" will come in on menu_channel, not textbox_channel, so you want to put that "CUSTOM" conditional up in the part of the listen() that's handling the menu_channel... and it should simply trigger the llTextBox() call. Then, the result of that llTextBox() call will come in on the textbox_channel, which is handled in that lower section of the listen(), where it will get the color vector as its message (assuming that's what the user types in to the textbox). I also notice that you're calling llTextBox() with textbox_handler where I think you instead want textbox_channel as its argument. [ETA: I also notice that the script is opening listens on both channels as soon as the menu is created, but won't remove the textbox_channel listen if any non-CUSTOM menu choice is made, so that will eventually leak all the listeners and the script will stop working. But that can be tidied up after the script starts working.] Edited November 2, 2020 by Qie Niangao 1 Link to comment Share on other sites More sharing options...
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