Jump to content

llListen question


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

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

Recommended Posts

Wow ok i would think this would be a busier place.

Anyway on the off chance, someone notices this post I was hoping someone could tell me why this script is not turning off the /12 listening event. It should have a 30 second timer and/or if the user changes their name it should turn off and stop listening. Or am totally not understanding the llListening. Tried to include as much documentation as i could

 

integer listenChannelForNickname = 12; // Channel to listen for the nickname
integer sendChannel = 9999; // Channel to send the nickname to the name script
integer obscureChannel = -73259; // The obscure channel for internal communication
string textureOptions = "e30f4002-5002-2f42-b2ae-25edbf5f7640"; // Texture UUID
integer isListening = FALSE; // Flag to control the listening state
integer listenHandle = -1; // Initialize with an invalid handle

default {
    state_entry() {
        // The listener is not initialized here
    }

    touch_start(integer total_number) {
        key userID = llDetectedKey(0);

        // Check if the toucher is the owner
        if (userID == llGetOwner()) {
            vector touchST = llDetectedTouchST(0);
            float u = touchST.x;
            float v = touchST.y;

            // Check if the touch is within the button's UV coordinates
            if (u >= 0.805888 && u <= 0.984350 && v >= 0.698508 && v <= 0.740167) {
                llOwnerSay("Please type in chat /12 YourNewNickname.\nOr type /12 Reset to reset your name.");

                if (!isListening) {
                    listenHandle = llListen(listenChannelForNickname, "", llGetOwner(), "");
                    isListening = TRUE;
                    llSetTimerEvent(30.0);
                }
            }
        }
    }

    listen(integer channel, string name, key id, string message) {
        if (channel == listenChannelForNickname && id == llGetOwner() && isListening) {
            // Process the message
            if (llToLower(message) == "reset") {
                string originalName = llKey2Name(llGetOwner());
                llSay(sendChannel, "SetNickname: " + originalName);
            } else {
                llSay(sendChannel, "SetNickname: " + message);
            }

            llMessageLinked(LINK_SET, obscureChannel, "idleoption," + textureOptions, NULL_KEY);

            // Notify owner and stop listening and timer
            llOwnerSay("Nickname set. No longer listening.");

            // Stop listening and timer, and ignore any further messages
            llListenRemove(listenHandle);
            llSetTimerEvent(0.0);
            isListening = FALSE;
            listenHandle = -1;
        }
    }

    timer() {
        if (isListening) {
            // Notify owner and stop listening and timer
            llOwnerSay("I am not listening anymore.");

            // Stop listening and timer
            llListenRemove(listenHandle);
            llSetTimerEvent(0.0);
            isListening = FALSE;
            listenHandle = -1;
        }
    }
}

Thank you for your time and efforts I do appreciate any assistance with this. Sorta Banging my head on the wall

  • Like 1
Link to comment
Share on other sites

No it does everything i am looking for the problem is if you want say 2 minutes and type /12 Superman and it changes the nickname. I only want it to change the nickname when the button is touched then you reset your name do whatever and then I want the script to stop listening to /12 other words i want to be able to reuse the /12 for other things to manually set

 

And wow thanks for the fast reply I wasn't expecting anything until tomorrowLOL

Link to comment
Share on other sites

As far as I can tell the script is working exactly as designed. I would have implemented this with llListenControl, rather than re-declaring the listener for every transaction, but the script as written avoids most of the easy pitfalls of the method. (one nitpick: you may want to move the llSetTimerEvent from line 28 to outside the if condition.)

What steps do you do, and what happens? How is what happens different from what you expect to happen?

(my interaction tests:)

Timeout:

  1. /12 Test
  2. <no response> (correct behavior)
  3. <touch the prim> (I removed the UV coordinate check from the script)
  4. Object: Please type in chat /12 YourNewNickname. Or type /12 Reset to reset your name.
  5. <wait 30 seconds>
  6. Object: : I am not listening anymore.
  7. /12 Test
  8. <no response> (correct behavior)

take one input:

  1. <touch the prim> (I removed the UV coordinate check from the script)
  2. Object: Please type in chat /12 YourNewNickname. Or type /12 Reset to reset your name.
  3. /12 test
  4. Object: : Nickname set. No longer listening.
  5. /12 test
  6. <no response> (correct behavior)
  • Like 1
Link to comment
Share on other sites

2 hours ago, Shatter Roundel said:

... other words i want to be able to reuse the /12 for other things to manually set

given that you might want the user to be able to change or reset their nickname at any and all times, then for other things you might want to use more than one listener channel. Like:

llListen(12, ... for nickname change

llListen(22, ... for other things

a script can have up to 65 open listen channels at one time: https://wiki.secondlife.com/wiki/LlListen

if you just want to use a single channel 12 then a way is to use a command prefix. For example where "nick" and "other" are commands:

/12 nick yourNewNickname

/12 nick reset

/12 other something

/12 other something else

parsing the message with for example:

       

        string message = " nick  yourNewNickName  ";  
              
        // trim any leading or trailing whitespace  
        message = llStringTrim(message, STRING_TRIM);
        
        // get index of space separting command from parameter
        integer space = llSubStringIndex(message, " ");
        
        // get the command
        string command = llToLower(llGetSubString(message, 0, space - 1));
        // get the parameter trimming any additional leading whitespace that may be there
        string parameter = llStringTrim(llGetSubString(message, space + 1, -1), STRING_TRIM_HEAD);
        
        if (command == "nick") .. do nick
        else if (command == "other" ... do other

 

 

Edited by elleevelyn
typs
Link to comment
Share on other sites

Maybe we should explore what would happen next to trigger the script to "reuse the /12 for other things to manually set". Like, would the owner touch another area—a different button—and the script listen on /12 for the owner to say something else rather than setting/resetting their nickname? Is it always only the owner whose touch triggers a listen on /12? Does something other than a touch cause the listen to start again? Should a touch ever cause the script to do something other than listen to the owner for a command?

  • Like 1
Link to comment
Share on other sites

I thank you all for your time and responses, for the life of me I can not figure this out.

 

 

It just doesn't do what I need it to do but ultimately I guess I can leave it active. I can not tell if maybe it is the Region I am working from or what it is. I will bounce around some see if it sets correctly. I have hit this from every which way but loose.

If anyone wants to throw a stick at this here is my final script.

The way it is supposed to work 

  1. User clicks on the button - This activates the listener
  2. The user has a couple of options to set their name on channel 12
  3. When the user types a name
    1. shuts down the listener
  4. or the 30 second timer runs out it
    1. shuts down the listener

The issue is the listener do not turn off, wait a couple of minutes click on anything do anything shy of a full object reset and you can always change the name without ever having to click on the button again.

integer listenChannelForNickname = 12;
integer sendChannel = 666;
integer obscureChannel = -999;
string textureOptions = "UUID_for_active_texture";
string textureIdle = "UUID_for_idle_texture";
integer listenHandle = -1;
integer optionsActive = FALSE;

default {
    state_entry() {
        listenHandle = llListen(listenChannelForNickname, "", llGetOwner(), "");
        llListenControl(listenHandle, FALSE);
        llOwnerSay("Script started. Listener inactive.");
    }

    touch_start(integer total_number) {
        key userID = llDetectedKey(0);
        vector touchST = llDetectedTouchST(0);
        float u = touchST.x;
        float v = touchST.y;

        if (userID == llGetOwner()) {
            if (u >= 0.805888 && u <= 0.984350 && v >= 0.698508 && v <= 0.740167) {
                llOwnerSay("Nickname change requested. Listening for 30 seconds.");
                llListenControl(listenHandle, TRUE);
                llSetTimerEvent(30.0);
            } else if (u >= 0.739200 && u <= 0.783677 && v >= 0.808898 && v <= 0.848837) {
                if (optionsActive) {
                    llSetTexture(textureIdle, 4);
                    llMessageLinked(LINK_SET, obscureChannel, "ae_options_close", NULL_KEY);
                    optionsActive = FALSE;
                } else {
                    llSetTexture(textureOptions, 4);
                    llMessageLinked(LINK_SET, obscureChannel, "ae_options", NULL_KEY);
                    optionsActive = TRUE;
                }
            }
        }
    }

    listen(integer channel, string name, key id, string message) {
        if (channel == listenChannelForNickname && id == llGetOwner()) {
            llListenControl(listenHandle, FALSE);
            llSetTimerEvent(0.0);

            if (llToLower(message) == "reset") {
                message = llKey2Name(llGetOwner());
            }
            llSay(sendChannel, "SetNickname: " + message);
            llMessageLinked(LINK_SET, obscureChannel, "idleoption," + textureOptions, NULL_KEY);
            llOwnerSay("Nickname set. Listener off.");
        }
    }

    timer() {
        llListenControl(listenHandle, FALSE);
        llSetTimerEvent(0.0);
        llOwnerSay("Timer elapsed. Listener off.");
    }
}

 Maybe the script will be useful to someone else, I mean it works for me just not exactly how I want it to.

I really do not have to turn it off so long as only the owner can make the changes

Again Thank you all so much for the assist.

Link to comment
Share on other sites

Just to comment on everyone's responses:

15 hours ago, Quistess Alpha said:

As far as I can tell the script is working exactly as designed. I would have implemented this with llListenControl, rather than re-declaring the listener for every transaction, but the script as written avoids most of the easy pitfalls of the method. (one nitpick: you may want to move the llSetTimerEvent from line 28 to outside the if condition.)

What steps do you do, and what happens? How is what happens different from what you expect to happen?

(my interaction tests:)

Timeout:

  1. /12 Test
  2. <no response> (correct behavior)
  3. <touch the prim> (I removed the UV coordinate check from the script)
  4. Object: Please type in chat /12 YourNewNickname. Or type /12 Reset to reset your name.
  5. <wait 30 seconds>
  6. Object: : I am not listening anymore.
  7. /12 Test
  8. <no response> (correct behavior)

take one input:

  1. <touch the prim> (I removed the UV coordinate check from the script)
  2. Object: Please type in chat /12 YourNewNickname. Or type /12 Reset to reset your name.
  3. /12 test
  4. Object: : Nickname set. No longer listening.
  5. /12 test
  6. <no response> (correct behavior)

For me steps 6 and 4 are where it breaks it just keeps listening so when i type /12 test... my name would change to "test". I have not seen llListenControl thank you for that info i tried to turn it odd and on with that.. didn't work for me but I will totally use it for future scripts. Thank you 

 

13 hours ago, elleevelyn said:

given that you might want the user to be able to change or reset their nickname at any and all times, then for other things you might want to use more than one listener channel. Like:

llListen(12, ... for nickname change

llListen(22, ... for other things

a script can have up to 65 open listen channels at one time: https://wiki.secondlife.com/wiki/LlListen

if you just want to use a single channel 12 then a way is to use a command prefix. For example where "nick" and "other" are commands:

/12 nick yourNewNickname

/12 nick reset

/12 other something

/12 other something else

parsing the message with for example:

       

        string message = " nick  yourNewNickName  ";  
              
        // trim any leading or trailing whitespace  
        message = llStringTrim(message, STRING_TRIM);
        
        // get index of space separting command from parameter
        integer space = llSubStringIndex(message, " ");
        
        // get the command
        string command = llToLower(llGetSubString(message, 0, space - 1));
        // get the parameter trimming any additional leading whitespace that may be there
        string parameter = llStringTrim(llGetSubString(message, space + 1, -1), STRING_TRIM_HEAD);
        
        if (command == "nick") .. do nick
        else if (command == "other" ... do other

 

 

Actually, this is brilliant hadn't thought of that, and is something I will use for some other parts of my HUD. However, for this to be honest I really do not need to reuse the channel I was just using the idea of reusing the channel as a way to explain it needing to turn off. I know it doesn't use a ton of resources to stay open listening forever but you know how it is, Always try to make the scripts be as efficient as possible.

 

10 hours ago, Qie Niangao said:

Maybe we should explore what would happen next to trigger the script to "reuse the /12 for other things to manually set". Like, would the owner touch another area—a different button—and the script listen on /12 for the owner to say something else rather than setting/resetting their nickname? Is it always only the owner whose touch triggers a listen on /12? Does something other than a touch cause the listen to start again? Should a touch ever cause the script to do something other than listen to the owner for a command?

Yes, it is supposed to only be the owner that can trigger the /12 command, it is purely a cosmetic thing though for the HUD. Since it is a HUD it is the touch event that makes the most sense to trigger the event,, i guess there could be other ways but this seems the most intuitive way.

 

Again thank you all for your responses I really appreciate it more than I can say!   😍

 

Link to comment
Share on other sites

45 minutes ago, Shatter Roundel said:

For me steps 6 and 4 are where it breaks it just keeps listening so when i type /12 test... my name would change to "test".

It doesn't do that for me. If I've supplied a nickname or typed "reset" on /12, or if the 30-second timer expires, the script no longer responds to channel 12; that listener is gone, as one would expect from the code.

So why does it keep listening for you? Is there any chance there's something else in your test environment listening on /12? An earlier version of the script in another link of the HUD attachment, or in another attachment, or somewhere? 

  • Like 1
Link to comment
Share on other sites

3 hours ago, Qie Niangao said:

It doesn't do that for me. If I've supplied a nickname or typed "reset" on /12, or if the 30-second timer expires, the script no longer responds to channel 12; that listener is gone, as one would expect from the code.

So why does it keep listening for you? Is there any chance there's something else in your test environment listening on /12? An earlier version of the script in another link of the HUD attachment, or in another attachment, or somewhere? 

Hmm, that is crazy literally nothing of mine floating around here that listens to that channel but as soon as I went to a cleared sandbox it had no issues at all worked perfectly... I mean least I know now I am not losing my mind. I wonder if there is something in the Linden homes listening to that channel I wonder if it is just too close to often-used channels? I think I will change it up to be another channel altogether so my players do not have the issues. Thank you so much Qui and you may even have saved me a future bug report. Thank you again and thank you all for your assistance I was seriously questioning my sanity.

  • Like 2
Link to comment
Share on other sites

3 hours ago, Shatter Roundel said:

I wonder if there is something in the Linden homes listening to that channel

when you're scripting in a somewhat cluttered space, it's easy to accidentally move a script into something you don't intend to have a script in it (ex. the wall of your house) Sure would be nice if SL had a function to list all scripts in an area/parcel, but I digress. . .

  • Like 1
Link to comment
Share on other sites

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