Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Restricting listeners only to time input is expected.

Mortus Allen
Registered User
Join date: 28 Apr 2007
Posts: 528
02-06-2008 08:04
I have several "Rez Pads" for my vehicles than use dialog boxes. At current they have their listeners on all the time. As they are not on 0 it is likely not terrible but as they are touch activated I want them to only listen after they have been touched and then stop listening when a selection is made or after a time out. Now my question:

What is the best and most lag efficient way to turn off the listener in a script llListenRemove or llListenControl?

Thanks in advance.
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
02-06-2008 09:16
If you want it to stop after a certain time you can use the timer() event.

ie:

in the same line you launch the dialog add:

llSetTimerEvent(seconds);

and in timer event:

timer()
{
llListenRemove(listener);
llSetTimerEvent(0.0); // this will kill the timer
}

-----

That way if the menu is not active for x seconds it will kill the listener.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-06-2008 09:33
I don't know of any significant performace difference between llListenRemove() and llListenControl(). If you plan to restart the exact same listen (same channel and filters and everything), you might as well use llListenControl(). If you want to jump channels for security or change the filter to the person who touched the object or anything, you'll have to use llListenRemove().
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-06-2008 10:09
if you open multiple listens (like one for each person), you can chain the timeouts, and change states to an empty state (and then back again) when the timer triggers. the timer will only trigger X seconds after the call, so any call to the set timer before that effectively extend it X more seconds, up until it's not interupted
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Mortus Allen
Registered User
Join date: 28 Apr 2007
Posts: 528
02-06-2008 10:39
Here is my current script.

//gives inventory to object when it rezzes.
string inventory;
string object;
list obj_list;
list obj_menu;
integer num_objects;
integer channel = 1000;
integer counter;

default
{
state_entry()
{
llListen(channel,"", "","";);
num_objects=llGetInventoryNumber(INVENTORY_OBJECT);
}
changed(integer change)
{
if(change & CHANGED_INVENTORY)
{
llResetScript();
}
}
touch_start(integer count)
{
if(llDetectedKey(0) == llGetOwner())
{
if(num_objects != 0)
{
counter = 0;
obj_list = [];
obj_menu = [];
for (counter = 0; counter < num_objects; counter++)
{
obj_list += [(string)counter + ".) " + llGetInventoryName(INVENTORY_OBJECT,counter)];
obj_menu += [(string)counter];
}
llDialog(llDetectedKey(0), "Select VTAL to Rez by number from the following list:\n" + llDumpList2String(obj_list, ", ";) + ".",obj_menu,channel);
}
else
{
llSay(0,"This rez pad has no VTALs to rez.";);
}
}
else
{
llSay(0,llDetectedName(0) + ", you are not authorized to use this rez pad.";);
}
}
listen(integer chan, string name, key id, string mes)
{
object=llGetInventoryName(INVENTORY_OBJECT,(integer)mes);
llRezAtRoot(object, llGetPos() + <1.0, 0.75, 1.25>, ZERO_VECTOR, <0.0,0.0,1.0,2.0>, 0);
}
}

Sorry not a lot of comments, was really bad at that when I wrote it. Anyway is has an open listener on channel 1000 which on my land = 3 such listeners and one reason for wanting to restrict them. Second is proximity, I have two close together so I had to change the channel on the other so it did not rez when the other one did, this works but means I have to be mindful of this when I update the scripts. And the biggest reason is to reduce any lag I may be causing, though this may be minimal.

So my thoughts were to only have the listener listen after the pad has been touched inside the IF that checks if the person that touched it is the owner, then turn off the listener once the input is received or after a time out.
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
02-06-2008 16:35
CODE


//gives inventory to object when it rezzes.
//string inventory;
string object;
list obj_list;
string name;
list obj_menu;
integer num_objects;
integer channel = 1000;
integer counter;
integer handler;//this is used to kill and get back the listen
float TimeR=0.0;//second for the timer
default
{
state_entry()
{
num_objects=llGetInventoryNumber(INVENTORY_OBJECT) ;
//********************
llSetTimerEvent(TimeR);//set the timer in this case 0
name=llKey2Name(llGetOwner());
//*************************
}
changed(integer change)
{
if(change & CHANGED_INVENTORY)
{
llResetScript();
}
}
touch_start(integer count)
{
if(llDetectedKey(0) == llGetOwner())
{
if(num_objects != 0)
{//*********************
llSetTimerEvent(20.0);//timer set to the timer event
handler=llListen(channel,"", "","");//open the listener
//*************************
counter = 0;
obj_list = [];
obj_menu = [];
for (counter = 0; counter < num_objects; counter++)
{
obj_list += [(string)counter + ".) " + llGetInventoryName(INVENTORY_OBJECT,counter)];
obj_menu += [(string)counter];
}
llDialog(llDetectedKey(0), "Select VTAL to Rez by number from the following list:\n" + llDumpList2String(obj_list, ", ") + ".",obj_menu,channel);
}
else
{
llSay(0,"This rez pad has no VTALs to rez.");
}
}
else
{
llSay(0,llDetectedName(0) + ", you are not authorized to use this rez pad.");
}
}
listen(integer chan, string name, key id, string mes)
{
object=llGetInventoryName(INVENTORY_OBJECT,(integer)mes);
llRezAtRoot(object, llGetPos() + <1.0, 0.75, 1.25>, ZERO_VECTOR, <0.0,0.0,1.0,2.0>, 0);
}
//*************
timer()//timer trigered when the llSetTimerEvent was set to some number
{
llSay(0,"Sorry time is up "+name +" try again.");
llListenRemove(handler);//remove the listener
llSetTimerEvent(0.0);//set the timer to zero
}
//**************
}

[\CODE]

I hope this was helpfull.
Boreal Latte
Registered User
Join date: 15 Nov 2007
Posts: 104
Perhaps make two states
02-06-2008 23:20
An other way to make it only listen when touched is to make two states. When touched, go to a different state where you are listening. In that state you might also not react to touch. When you are done listening, you can return the the first state, where you react to touch again. Something along the following lines.
default
{
touched(..)
{
state listening;
}
}

state listening
{
state_entry()
{
llListen(...);
}
listen(...)
{
... do your stuff ...
state default;
}
}
I have used it in some poseballs which only listens to show and hide when they are not used. This prevents them to appear in the body of avatars sitting.