Jump to content

llTextBox to set Text, not triggering Listen event


Derin Swenson
 Share

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

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

Recommended Posts

	listen(integer chan, string name, key id, string mes) 
    {
        llOwnerSay("Debug: Channel - " + (string)chan + ", id - " + llKey2Name(id) + ", message - " + mes + ".");
        if(id == owner)
        {
           if(llToLower(llGetSubString(mes,0,llStringLength("titler ") - 1 )) == "titler ")
           {
               integer num = (integer)llGetSubString(mes, llStringLength( "titler " ), -1);
               llOwnerSay((string)num);
               llListenRemove(listenhandle);
               listenhandle = llListen(-num, "", owner, "");
               if(num == 1)
                    llTextBox(owner, "Set line " + (string)num + " for titler.", -num);
               else if(num == 2)
                    llTextBox(owner, "Set line " + (string)num + " for titler.", -num);
               else if(num == 3)
                    llTextBox(owner, "Set line " + (string)num + " for titler.", -num);
               else if(num == 4)
                   	llTextBox(owner, "Set line " + (string)num + " for titler.", -num);       
            }
        }
        
        if(id == owner)
        {   
            llOwnerSay("Debug: Channel recieved " + (string)chan);
            if(chan == -1)
                line1 = mes;
            else if(chan == -2)
                line2 = mes;
            else if(chan == -3)
                line3 = mes;
            else if(chan == -4)
                line4 = mes;
            llListenRemove(listenhandle);
        	titlerreset(); 
    	}
	}

I have this command, (general chat listener set in state entry event) that will open up a textbox, and then send the input into one of four lines depending on the command.  I.E.  "titler 1"  changes line 1, "titler 2" changes line 2, all the way up to line 4.  It takes the command and gets the last character and uses that as a negative channel for the textbox dialog.  When I input what I want the new line to say, then click submit, my listen event doesn't trigger.

I left my debug owner says in there.  The top one just under the listen event header doesn't fire off when submit is clicked in the textbox.  I've checked to make sure the listen is created in the listen handler, and it does.   owner is set to llGetOwner() in the stateentry and titlerresetI() just resets the SetText.  

Am I doing something wrong?  I used the Textbox2Hovertext as the basis of this script.

Link to comment
Share on other sites

Your problem is that the llListenRemove(listenhandle); command in the second if statement removes the listener you set up with listenhandle = llListen(-num, "", owner, ""); in the first if statement before the user has a chance to enter any text in the box and click the submit button.

Rather than have 2 instances of if (id == owner) (both of which will be true when the listen event is triggered by either the titler command or the text box submit button) you could put the code from the second if statement inside the first using else so that it's executed when if(llToLower(llGetSubString(mes,0,llStringLength("titler ") - 1 )) == "titler ") is false, like so...

listen(integer chan, string name, key id, string mes) 
{
	llOwnerSay("Debug: Channel - " + (string)chan + ", id - " + llKey2Name(id) + ", message - " + mes + ".");
	if (id == owner)
	{
		if (llToLower(llGetSubString(mes,0,llStringLength("titler ") - 1 )) == "titler ")
		{
			integer num = (integer)llGetSubString(mes, llStringLength( "titler " ), -1);
			llOwnerSay((string)num);
			if ((num >=1) && (num <= 4)) {
				llListenRemove(listenhandle);
				listenhandle = llListen(-num, "", owner, "");
				llTextBox(owner, "Set line " + (string)num + " for titler.", -num);
			} else {
				llOwnerSay("Error: No Such Line");
			}
		} else {   
			llOwnerSay("Debug: Channel recieved " + (string)chan);
			if (chan == -1) {
				line1 = mes;
			} else if (chan == -2) {
				line2 = mes;
			} else if (chan == -3) {
				line3 = mes;
			} else if (chan == -4) {
				line4 = mes;
			}
			llListenRemove(listenhandle);
			titlerreset(); 
		}
	}
}

 

Note: You also had a potential problem with the existing listener being removed and no new listener being created if the user entered a command with an invalid titler line number (eg "titler 5") plus the 4 if (num) statements each containing the same llTextBox(owner, "Set line " + (string)num + " for titler.", -num); command seemed a little redundant, so I replaced them with a single if ((num >=1) && (num <= 4)) then moved the llListenRemove and llListen commands into that and added an else statement to let the user know when an invalid line number has been specified (of course you're still going to have a problem if someone tries to set the text for a line using "titler" as the first word:P).  I also added some brackets to your other if statements, cos you can never have too many brackets?! ;)

  • Like 1
Link to comment
Share on other sites

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