Difference between revisions of "Talk:Textbox2Hovertext"

From Second Life Wiki
Jump to navigation Jump to search
(Owner vs Toucher confusion)
Line 27: Line 27:


[[User:Omei Qunhua|Omei Qunhua]] 07:01, 29 January 2013 (PST)
[[User:Omei Qunhua|Omei Qunhua]] 07:01, 29 January 2013 (PST)
'''Owner vs Toucher'''
Actually I now see that there is confusion between toucher and the person who gets the textbox. The original code had this line:
<lsl>
        llTextBox( llDetectedKey(0), "Set Hovertext", (listenhandle = llListen(1, "", llGetOwner(), "")) );
</lsl>
Which sends a text box to the person who touched the object, but listens for a reply from the owner only (who is not necessarily the same person, or even online at the time).  It also had the confusion between channel number and listener handle as Strife pointed out.
However Strife's revision still has problems in the version intended for owner use only, as it responds to '''anyone''' touching the object, but sends the textbox to, and listens to a reply from,  the '''owner'''.
Better code for owner-only use would be:-
<lsl>
  touch_start(integer num)
    {
        key target = llDetectedKey(0);
        if (target != llGetOwner() )          // remove this 'if' and the 'return' to allow anyone to change the hover text
            return;
        llListenRemove(listenhandle);
        llSetTimerEvent(30.0);
        listenhandle = llListen(1, "", target, "");
        llTextBox( target, "Set Hovertext", 1 );
    }
</lsl>
[[User:Omei Qunhua|Omei Qunhua]] 07:24, 29 January 2013 (PST)

Revision as of 08:24, 29 January 2013

Listeners:

As your llListen() always has the same arguments (same channel and filtering by owner only) each llListen will be assigned to the same listener handle. So there's no danger of accumulating open listens, and your timer code could be simplified to:-

<lsl>

   timer()
   {
       llListenRemove(listenhandle);
       llSetTimerEvent(0.0);
   }

</lsl>

Unless your object gets handed on to multiple subsequent owners :)

If you want anyone to be able to set the hover text, then you could preclude multiple open listeners by removing the listen at the start of the touch event. It doesn't matter if it's already been removed by the timer code (or has never been assigned):-

<lsl>

  touch_start(integer num)
   {
       llListenRemove(listenhandle);
       key target = llDetectedKey(0);
       llSetTimerEvent(30.0);
       listenhandle = llListen(1, "", target, "");
       llTextBox( target, "Set Hovertext", 1 );
   }

</lsl>

Omei Qunhua 07:01, 29 January 2013 (PST)

Owner vs Toucher

Actually I now see that there is confusion between toucher and the person who gets the textbox. The original code had this line:

<lsl>

       llTextBox( llDetectedKey(0), "Set Hovertext", (listenhandle = llListen(1, "", llGetOwner(), "")) );

</lsl>

Which sends a text box to the person who touched the object, but listens for a reply from the owner only (who is not necessarily the same person, or even online at the time). It also had the confusion between channel number and listener handle as Strife pointed out.

However Strife's revision still has problems in the version intended for owner use only, as it responds to anyone touching the object, but sends the textbox to, and listens to a reply from, the owner.

Better code for owner-only use would be:-

<lsl>

  touch_start(integer num)
   {
       key target = llDetectedKey(0);
       if (target != llGetOwner() )          // remove this 'if' and the 'return' to allow anyone to change the hover text
           return;
       llListenRemove(listenhandle);
       llSetTimerEvent(30.0);
       listenhandle = llListen(1, "", target, "");
       llTextBox( target, "Set Hovertext", 1 );
   }

</lsl>

Omei Qunhua 07:24, 29 January 2013 (PST)