Talk:Textbox2Hovertext

From Second Life Wiki
Revision as of 11:28, 13 February 2013 by Ackley Bing (talk | contribs)
Jump to navigation Jump to search

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)

I wanted to make as few changes as possible. As a bit of secret knowledge, listen handles are allocated incrementally, the first to be returned is 1. So even if the script did open multiple handles it would eventually clean them all up with the timer, nor would it clean them up too quickly (just way too slowly). I don't approve of that bit of cleverness, since it relies upon the allocation of listen handles (which I don't recall it ever being specified) but it works so I'm not going to spoil someone else's fun on their userpage. The script wastes CPU time and can run out of listens but again, not my call. You are correct, I forgot to make sure that if you set it to owner that only the owner's click would set it in motion. -- Strife (talk|contribs) 11:03, 29 January 2013 (PST)
Maybe it's one thing putting it on your own user page, but another thing to then link it from the Wiki script library, whose rules say "Your script must be tested and working. This is a list of working, usable scripts."  :)) Omei Qunhua 11:24, 29 January 2013 (PST)
It works exactly as intended: For owners http://community.secondlife.com/t5/LSL-Scripting/SCRIPTING/m-p/1819191#M15173 :) --Ackley Bing 10:28, 13 February 2013 (PST)
Good point. -- Strife (talk|contribs) 22:12, 29 January 2013 (PST)