Jump to content

assigning unique listen channel to each objects


Xander Lopez
 Share

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

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

Recommended Posts

so lets say i have the basic dialog script which opens up a menu so you can either choose "Yes" or "No". I have 100 of the same objects that contains the same script. Let's say the example is shown as below. Notice these 100 objects are all listening to channel -99.

integer gListener;
default
{
    touch_start(integer total_number)
    {
        llListenRemove(gListener);
        gListener = llListen(-99, "", llDetectedKey(0), "");
        llDialog(llDetectedKey(0), "\nyour answer is?", ["Yes", "No" ] , -99);
        llSetTimerEvent(60.0);
    }
    listen(integer chan, string name, key id, string msg)
    {
        if (msg == "Yes") .....
        if (msg == "No") .....
    }
    timer()
    {
        llListenRemove(gListener);
        llSetTimerEvent(0.0);
    }
}

Now, if i assign a different channel to all these 100 objects, they would have no problem identifying whos "no" means for which object.  But I don't want to go thru and assigning a different channel to listen for 100 objects..

Is there anyway for each objects to listen to only "No" came from their own prim altho they are all listening to the same channel?

Edited by Xander Lopez
Link to comment
Share on other sites

Since you're removing the listen the timer, you could have it assign a random number when Touched

touch_start(integer total_number)
    {
        llListenRemove(gListener);
        integer chan = (integer)llFrand(-99)-99;
        gListener = llListen(chan, "", llDetectedKey(0), "");
        llDialog(llDetectedKey(0), "\nyour answer is?", ["Yes", "No" ] , chan);
        llSetTimerEvent(60.0);
    }
Link to comment
Share on other sites

No need to limit yourself to a choice of just 100 possible channel numbers. Less chance of cross-talk if you go for (almost) the full gamut of possible negative integers:  (integer) lFrand (−2147483648).

If you need a constant and predictable (but different for each object) channel number you could use part of the object's key as the basis: (integer) ("0x" + llGetSubString ((string) llGetKey (), -8, -1)) | 0x80000000. There is a very small chance of duplicating channels with this if two objects have the same digits at the end of their keys.

Link to comment
Share on other sites

With llListen() I recommend you set a global key for the agent/object you're listening to and validate it in the listen event.

Also, after using llListenRemove(), I recommend changing the global listen integer value to 0 so it also can be validated in the listen event.

The reasoning for this is something I recently discovered (BUG-228091) where llListenRemove() & llListenControl() are no longer culling queued listen events that I "swore" did years ago when I tested, built and relied on applications that used that (undocumented) behavior for years and only at the advent of LL recently (last year) changing listen/sensor event queuing priorities do I no longer see said behavior.

So your script would look like:

integer gListener;
integer gUser = NULL_KEY;
default
{
    touch_start(integer total_number)
    {
        llListenRemove(gListener);
        gListener = llListen(-99, "", gUser = llDetectedKey(0), "");
        llDialog(gUser, "\nyour answer is?", ["Yes", "No" ] , -99);
        llSetTimerEvent(60.0);
    }
    listen(integer chan, string name, key id, string msg)
    {
        if (gListener && (id == gUser)) //BUG-228091
        {
            if (msg == "Yes") .....
            if (msg == "No") .....
        }
    }
    timer()
    {
        llListenRemove(gListener);
        gListener = 0; //BUG-228091
        llSetTimerEvent(0.0);
    }
}

You validate gListener to verify the listen is active, in case you remove the listen while a new listen event is queued.

You validate gUser in case a new user touches the device while a listen event from your old user was already queued.

Zeroing the listen integer does not disturb the handle incrementing process.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

The widely used solution for a unique channel of an object is
key objectKey = llGetKey();
integer channel =  -1 * ("0x"+llGetSubString((string)objectKey(),-8,-1))

using the last 8 digits of its unique key.

S a m e  code for individual negative channels.
Just keep in mind that every time an object is rezzed it creates a new individual key.
.
So the mother sends on her -99 channel, and the children reply on individual channels, loaded with exactly the same script, sending first their own channel on the common -99 channel.. The mother might want to store names and channels.

Children answers can be written with an identifying part such as
<prim name> + "no" 
or
<objectKey> + "no"
separating the identfying part from the answer upon arrival

Edited by Badena
Link to comment
Share on other sites

in this case I would use Lucia's method to validate the key of the user/toucher combined with KT's method of using the key of the listening object to create the channel number

the comms collision window is reduced to: The same user touching two or more objects with the same last 8 chars of their uuid

Edited by Mollymews
window
Link to comment
Share on other sites

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