Jump to content

Sensor to Dialog Add & Remove AV's


James2018 Landar
 Share

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

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

Recommended Posts

  1. Hi Everyone
  2.  
  3. I'm having a problem with sensor to dialog(add av to access list)
  4.  
  5. list senl;
  6. list accessl;
  7. integer menu;
  8.  sensor(integer num_detected)
  9.     {
  10.         integer i;
  11.         string name;
  12.        
  13.         for(i=0;i<num_detected;i++)
  14.        
  15.         if(IsInList(senl, llKey2Name(llDetectedKey(i))))
  16.         {
  17.             //DO NOTHING
  18.         }
  19.         else
  20.         {
  21.             name = llKey2Name(llDetectedKey(i));
  22.             senl += name;
  23.         }
  24.         llListSort(senl,2,FALSE);
  25.        
  26.         integer listlen = llGetListLength(senl);
  27.         for(i=0; i<listlen; i+=2)
  28.         {
  29.             name = llList2String(senl,i+1);
  30.         }
  31.     }
  32.     listen(integer chan, string name, key id, string msg)
  33.     {
  34.         if(menu == whatever)
  35.         {
  36.             if(msg == "Add")
  37.             {
  38.                 llDialog(id,"Av's that are around",sensl,scriptc);
  39.                 accessl += msg;
  40.                 llOwnersay((string)msg + " was added to the access list");
  41.             }
  42.         }
  43.     }
  44. }
  45. what I'm trying to do is choose an av's name  from the sensor to dialog menu, which ever av I choose I want that name to be added to access list.
  46.  
  47. not ('Add' was added to the list.)
  48.  
  49. Any ideas?
Link to comment
Share on other sites

That's not quite the way a llDialog is going to have to work.  If the listen event hears the prompt "Add" ( I assume it's coming on a chat channel that you have set previously), then...

1. it triggers the llDialog function, which ends its message on the channel you've called scriptc.

2. THEN the listen event captures the response from the llDialog.

3. and adds it to the access list.

So, the event has to be triggered twice, on two different channels and with different messages. But that's not what you wrote.  What you need is more like

 

listen (integer channel, string name, key id, string msg){    if(msg == "Add")    {        llDialog( id, " \n Detected avatars ...", sensl, scriptc);    }    else if (!~llListFindList(sensl,[msg]) )    {        access += [msg];        llOwnerSay( msg + " was added to the access list.");    }}

 On a side note, I don't have a clue what you are doing between lines 24 and 30.  You're getting values of name out of sensl that you just put there.  I also don't know what you're testing in line 34.  I assume that you do, though, and that's what counts.

 ETA:  BTW, I'm also assuming that you have opened a llListen on both of the channels you're using, elsewhere in the script. 

Link to comment
Share on other sites

You just lost me with that one.  The answer is the same, though.  You can listen for a lot of messages in the same listen event, but you have to set appropriate filters so that you know which one is which.  If you need to check whether the message is a key word in some list named "menu", you need to ask

if (~llListFindList(menu, [msg]))     // If TRUE then Yes, it is, so do something

If you thoughtlessly used the same keyword in two lists, you'll need to do some other sort of filter (or change your lists).....

if ((~llListFindList(menu, [msg]))  && (channel == gMnuChnl2) )  // msg is coming on a specific channel. Ignore the same word on a different channel.

Link to comment
Share on other sites

  • 4 weeks later...

Okay, it's still not working for some reason prompt "Remove" is the only msg that get added to access list.

 

//GLOBALS//----------//INTEGERS//----------integer freq = 1;integer scriptc = 283638;//LIST//---------list sensl; //sensor listlist accessl; //access list//FUNCTION//-----------integer IsInList(list data, string msg){    integer i;    for(i=0; i<llGetListLength(data);i++)    {        if(llList2String(data,i) == msg)        {            return TRUE;        }    }    return FALSE;}default{    state_entry()    {        llSensorRepeat("","",AGENT,20,PI,freq);        llListen(scriptc,"","","");    }    touch_start(integer x)    {        llDialog(llDetectedKey(0),"Sensor To Dialog Access and Removal Script",["Add","Remove"],scriptc);    }    sensor(integer num_detected)    {        integer i;          string name;        for(i=0;i<num_detected;i++)        if(IsInList(sensl,llKey2Name(llDetectedKey(i))))        {            //DO NOT ADD THE SAME AV"S NAME        }        else        {            if(llStringLength(name) >24)//if name characters are greater that 24            {                name = llGetSubString(name,0,23);            }            name = llKey2Name(llDetectedKey(i));            sensl += name;        }    }        listen(integer channel, string name, key id, string msg)    {        if(msg == "Add")        {            llDialog( id, " \n Detected avatars ...", sensl, scriptc);        }        else if (!~llListFindList(sensl,[msg]) )        {            accessl += [msg];            llOwnerSay( msg + " was added to the access list.");        }    }}

 

 

 

Link to comment
Share on other sites

Well, that's what you told the script to do.  Your listen event says ...

1. If the message is "Add", create a new Dialog

2. If the message is anything else (like "Remove"), check to see if it is already on the list called sensl.

3. If the message is not on the list called sensl, add it to the list called accessl, and let me know.

So that explains why the word "Remove" is added to the list.  So why aren't any of the detected names added?  Look back at the sensor event.  The entire for loop is being ignored because there are no curly brackets around its scope.  The sensor event should be written

    sensor(integer num_detected)    {        integer i;          string name;        for(i=0;i<num_detected;i++)        {            if (!~llListFindList(sensl,[llDetectedName(i)]))            {                name = llDetectedName(i);

if(llStringLength(name) >24)//if name characters are greater that 24 { name = llGetSubString(name,0,23); } sensl += [name]; } } }

 The way it's written now, no names are being added to the sensl list at all.

EDIT:  It would help if I could write something without making typos.  Sheesh.  Fixed.

Link to comment
Share on other sites

But that is the issue, I want the names that was sense to be added to list sensl(sensor list), because I want to use that sensor list in a dialog menu (as dialog buttons "av's names that was detected"    [bob, Joe, Doe]    ) to choose who has access to script object.

llDialog(id, "DetectedAv's..\nChoose which av that you would like to have access to this object. " ",sensl,scriptc);

When the owner choose "Bob" or who ever from the dialog menu I want the name "Bob" to be added to accessl(access list).

Link to comment
Share on other sites

Exactly.  But your sensl list is never being loaded correctly because your sensor event is all messed up.

When you have a problem like this, the best way to see what's going on is to pepper your script with strategically placed llOwnerSay commands.  Try asking llOwnerSay(llList2CSV(sensl)) at the end of the sensor event and then again in the listen event.

Link to comment
Share on other sites

Actually, even the corrected sensor event that I just gave you contains a flaw.  If the detected name is more than 24 characters long, it is truncated before it's stored in sensl.  If the same name is encountered a second time, the long version is compared against the truncated version.  The two obviously won't match, so the truncated name will be added again .... and again... and again....  What you really want is

    sensor(integer num_detected)    {        integer i;          string name;        for(i=0;i<num_detected;i++)        {            name = llDetectedName(i);            if(llStringLength(name) >24)//if name characters are greater that 24            {                name = llGetSubString(name,0,23);            }            if (!~llListFindList(sensl,[name]))            {                sensl += [name];            }        }    }

 BTW, I assume you know that the sensor event will only detect the 16 closest avatars that are within its range.

.

  • Like 1
Link to comment
Share on other sites

Maybe I've missed something, but is it really necessary to store the list of detected avatars indefinitely?   I can see circumstances in which it would be but I'd think for something like this, it probably wouldn't apply.

When I'm doing this sort of thing, I clear the detected list each time, when the sensor starts, on the argument I'm not usually going to interested in who I might have detected several days ago when adding someone to the list.    Instead, I'd want to check they're not already on the access list, since I don't want to risk adding them twice by mistake (which would complicate matters later on, if I decided to remove them).

Link to comment
Share on other sites

Good point, Innula.  That sensor event really ought to start with sensl = [];   This is one of the best reasons for using Void's convention of tagging global variables with a "g".  I always do that in my own scripts, so that I don't lose track of which variables persist across events and states.  I wasn't paying attention to that one.

Link to comment
Share on other sites

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