Jump to content

Script optimization questions (llListen)


jackiejill
 Share

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

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

Recommended Posts

Hey everybody, first post here on these forums, 


I am helping development for a virtual world on OpenSim and we have been having some trouble with our servers overloading. I want to go through our scripts and optimize them a little. One function we use a lot is the llListen function for prims to communicate with each other region wide. I understand that llListen, if implemented poorly, can cause unnecessary stress on the servers.  
So, what are some ways to make llListen functions and their subsequent scripts more efficient?

Link to comment
Share on other sites

I don't know how it works on OpenSim, but in SL the problem isn't so much listeners as open listeners on channels where there's a lot of activity.

The classic explanation of how the listen event works was given by Kelly Linden at  https://lists.secondlife.com/pipermail/secondlifescripters/2007-November/001993.html

So, in general, use very negative channels (or, I guess, very positive ones -- while an avatar could speak on channel 82974531 I can't believe that, in practice, anyone would be insane enough to expect many people so to do), so the sim doesn't need to do lots of unnecessary checks after discovering your object is the only thing on the sim listening on that channel.    

A lot of people don't realise it, but vast amounts of resources are wasted by the sim having to do lots of needless work every time someone says anything on channel 1 because every single freebie poseball script on the sim pricks up its little virtual ears in case it's supposed to show or hide the poseball.

When possible, use llRegionSay, so it doesn't need to check if the object should be able to hear the message (or, if OpenSim has it and you can readily grab the key of the object you're talking to, llRegionSayTo is even better, because that way it just goes straight to the object anyway), and, if possible, do your filtering in the listener rather than the listen event ( so llListen(-123456,"",llGetOwner(),"") in state_entry rather than if (id==llGetOwner()) in the listen event).

But most important, close down your listeners with llListenControl or llListenRemove the moment you don't need them any more.

  • Like 1
Link to comment
Share on other sites

1. Avoid using channel numbers that are in common use ( one- to three-digit positive integers, or numbers like 1111,12345).  Use high, negative numbered channels instead.  Avoid using the public chat channel unless absolutely necesary.

2. Filter llListen to listen only to messages from specific sources.

3. Use llListenRemove or state changes to kill llListen when not needed.  Use timeouts on dialogs and textboxes.

4. Use llRegionSayTo instead of llRegionSay to target sim-wide messages to specific objects.

5. Use the same llListen for several expected messages instead of opening new instances.

6. Consider using llGiveInventory to share information on a notecard instead of sending a chat message.

That last one is particularly handy for sending update information to several remote objects in the sim at once. Drop the new information on a notecard into a central transmitting object and have it send copies to the remotes, where the information is read and incorporated.

Link to comment
Share on other sites

Keep listens open only when they are necessary. For instance if your object sends a menu via llDialog() on touch or any event other than in-channel command, close the listen after a response is received or the menu times out (always time the menu response). The implementation looks something like this:

UserMenuMethod(key user_id)
{
  string menu_text = ...;                       // whatever the text is  
  list menu = ...;                                    // whatever the menu list is
   
  integer channel;
  while(!channel)
     channel = (integer)llFrand(123456789.0);
  handle = llListen(-channel, "", user_id, "");     // global handle
  llDialog(user_id, menu_text, menu, -channel);
  llSetTimerEvent(USER_WINDOW);                 // global parameter I usually set to 120 sec
}

default                                         // or any other state
{
  ...
  ...

  listen(integer ch, string name, key id, string mes)
  {
    llSetTimerEvent(0.0);
    llListenRemove(handle);
    ProcMenuCommand(id, mes);                   // user function    
  }

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

  touch_start(integer num_detected)             // or whatever event
  {
    UserMenuMethod(llDetectedKey(0));      
  }     
}

If there are other things to time, it may become a lil more complex but still doable.

Link to comment
Share on other sites

Hi im struggling to work on a HUD that i will allow a funtction only after it has heard 5 passwords.

I'm not a great Scripter and i think it has something to do with changing an integer meaning, but i cant get my head round it so as a last resort ive come bac to the forum for assistance.

Basically i have 5 objects that say a password, and the HUd needs to hear all 5 passwords before it will open up a new function. Is this possible and how?

Thank you

 

Loki

Link to comment
Share on other sites

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