ZachSmith Posted June 27, 2012 Share Posted June 27, 2012 This is a simple example I made of the fairly new llTextBox. This is free software for anyone to use or learn with. Please use as you like just keep it free software.////////////////////////////// //Made by ZachSmith Resident// ////////////////////////////// //Global Variables// integer listen_handle; string detected_name; //Default State// default { //Touch_Start event for when the item is touched// touch_start(integer total_number) { //Set the channel to be a random float that is rounded to the nearest integer since channels cannot be non whole numbers. integer channel = llRound(llFrand(10000)); //save the name of the person touching to a variable to be used later detected_name = llDetectedName(0); //set the llListen function to listen on channel for message from the key of the detected toucher listen_handle = llListen(channel, "", llDetectedKey(0), ""); //give instructions on how to use llSay(0, "Please type your suggestion in the Text Box and then press send. You have 2 minutes"); //Show the text box for them to put a message into llTextBox(llDetectedKey(0), "Type your suggestion below", channel); //set a timer event for 2 minutes giving them plenty of time to type a message so we can then close any listeners. llSetTimerEvent(120); } //listen event which is a result of the llListen listen(integer channel, string name, key id, string message) { //Instant message the owner and tell them the name and suggestion that was just typed in the text box llInstantMessage(llGetOwner(), detected_name + ": " + message); //remove the listener to help reduce lag llListenRemove(listen_handle); //turn the timer event to 0 so it does not continue going off every 120 seconds llSetTimerEvent(0); } //timer event, result of the llSetTimerEvent timer() { //tell the user that they are out of time and must click again to reopen the listen llSay(0, "Sorry, you did not type your message fast enough and has timed out. Please try again."); //remove the llListen so it will take less resources llListenRemove(listen_handle); //set timer event to 0 so it will not continue to say they have run out of time. llSetTimerEvent(0); } } //string name = ZachSmith Resident;// //integer value = TRUE;// ///////llSetAwesome(name, value);/////// 1 Link to comment Share on other sites More sharing options...
Rival Destiny Posted June 27, 2012 Share Posted June 27, 2012 This is awesome thanks! Will replace my suggestion box at my store. Wonderful Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 27, 2012 Share Posted June 27, 2012 Or ... integer gTChan;integer gLisn;default{ state_entry() { gTChan = (integer)("0xF" + llGetSubString(llGetKey(),0,6)); } touch_end(integer num) { llListenRemove(gLisn); gLisn = llListen(gTChan,"",llDetectedKey(0),""); llTextBox(llDetectedKey(0)," \nType your suggestion and click \"Submit\".",gTChan); llSetTimerEvent(120.0); } listen( integer channel, string name, key id, string msg) { llListenRemove(gLisn); llSetTimerEvent(0.0); llInstantMessage(llGetOwner(), llKey2Name(id) + ": " + msg); llRegionSayTo(id,0,"Thank you. Your message has been sent."); } timer() { llSetTimerEvent(0.0); llListenRemove(gLisn); }} Link to comment Share on other sites More sharing options...
ZachSmith Posted June 27, 2012 Author Share Posted June 27, 2012 Well, I do appreciate your feedback. I am sure no one was calling you dumb. However I did use a randm channel rather than key generated because I prefer it in item that will not be talking to other scripts because there are to many item that are key generated channels and less chance of hitting the random channel than another scriptor who used the same code snippet. However I will point out my own mistake that I forgot to put +1 for the channel to make sure it never hits PUBLIC_CHANNEL. Other than that though all I see that was changed was the name of the variables. Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 27, 2012 Share Posted June 27, 2012 There's very little chance of crosstalk. A channel based on the object's key is as random as one selected with llFrand(10000), since each object's UUID is unique. In fact, it offers many more random channels than the roughly 10,000 that llFrand(10000) does. Even if some other scripter is using the same method, her/his objects will have a channel based on their own UUID, not this object's. Note also that objects should normally talk to each other on negative channels to avoid the possibility that an avatar might hijack the conversation. That's a trivial possibility in this case, of course, but still a good habit to be in. That's why I always prefix my channel with (integer)("0xF"). Link to comment Share on other sites More sharing options...
Innula Zenovka Posted June 28, 2012 Share Posted June 28, 2012 May I suggest a slight modification, to get rid of one of my pet peeves, that is, using llDetectedName() and similar, and thus not handling any accounts created since November 2010 (?) particularly elegantly and not handling display names at all? I've also added something I find useful for messaging systems -- a link to open an IM window with the person who left the message. listen(integer channel, string name, key id, string message) { llListenRemove(gLisn); llSetTimerEvent(0.0); //display name handing from Cerise Sorbet's Display Names Radar, //http://wiki.secondlife.com/wiki/Display_Names_Radar string legName = name; list nameParts = llParseString2List(legName, [" "], []); if (llList2String(nameParts, 1) == "Resident"){ //drop the "Resident" placeholder if found legName = llList2String(nameParts, 0); } string showName = legName; string dispName = llGetDisplayName(id); if (dispName){ // if the display name isn't the same as the username, show both if (llToLower(dispName) != llToLower(legName)){ showName = dispName + " (" + llGetUsername(id) + ")"; } } string app_im = "secondlife:///app/agent/"+(string)id+"/im"; llInstantMessage(llGetOwner(), showName + ": " + message+ "\nClick here to return the message:" +app_im); llRegionSayTo(id,0,"Thank you. Your message has been sent."); } Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 28, 2012 Share Posted June 28, 2012 I like it, Innula. I can't see any point in using llDetectedName in a script like this and having to save it globally either, which is why I went with llKey2Name(id). That doesn't deal with the nasty mess of "Resident" and Display Names, though. Frankly, my own cowardly solution has been to ignore them and stop refering to people by name unless truly necessary, but I like Cerise's code. Thanks for posting your version. Link to comment Share on other sites More sharing options...
Rival Destiny Posted June 28, 2012 Share Posted June 28, 2012 OK so to put the script together, I would just add your part Innula? Link to comment Share on other sites More sharing options...
Innula Zenovka Posted June 28, 2012 Share Posted June 28, 2012 @Rolig.. glad you liked it. I've found Cerise's code really useful for sorting out what you so aptly describe as the "nasty mess" of legacy/user/display names. @Rival ... I based it on Rolig's code, so just substitute my listen event for hers. Link to comment Share on other sites More sharing options...
Rival Destiny Posted June 28, 2012 Share Posted June 28, 2012 ah ok thank you! edited to add - or substitue the OP's with either yes? tia Am just a tad past Hello Avatar in scripting but love to learn. Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 28, 2012 Share Posted June 28, 2012 You could substitute Innula's code for the listen event in either version --- or in the example at https://wiki.secondlife.com/wiki/LlTextBox, which is the same code. Her elegant solution for handling name variants is not specific to llTextBox, so it can be applied to any similar messaging script. Same thing with my observations about comm channels, which were meant to (1) make channel selection a one-time process instead of doing it every time you trigger touch_start, and (2) increase the number of available unique negative comm channels. Link to comment Share on other sites More sharing options...
Innula Zenovka Posted June 28, 2012 Share Posted June 28, 2012 If you want to learn scripting, you've come to the right place -- Scripting Tips is where I learned, certainly, and so did most of the regulars. As to the listen event, you can substitute the OP's listen event with either, so long as you change Rolig's line (which I adopted) about llListenRemove(gLisn); to llListenRemove(listen_handle); The two mean the same. It's just Rolig and the OP used different names for the integer variable that's being stored. That's the only change I can see that would be needed, but I can't get in to check. 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