Jump to content
teresasama

Need help with List

Recommended Posts

Hello, I wanna make a list of usernames which checks if there's any matches with avatars in the same sim, I'm not good at scripting but I guess we can take advantage of llGetAgentSize(id), llSetTimerEvent(0.1) and timer() in order to keep checking the list every 0.1 ms.

For example: list x = ["user A", "user B", "user C"];
If user A is present, it returns to me: llOwnerSay(user A);

However if more than 1 username in the list are present, it must return just 1 username either A, B or C.

Share this post


Link to post
Share on other sites

First, you don't need llGetAgentSize for anything. After all, if you detect a person, you already know he's there.  Just gather your list with llGetAgentList. Those will be UUIDs, but unless you really need to know all names, that should be enough. If you do need names, you can always get them from the UUIDs with llKey2Name.

Second, it's overkill to query the region every 0.1 seconds.  The list of people there won't change that fast, so a rapid timer is a waste of server resources.  You should be able to get by with a query every 5 seconds or so.

Now, I don't quite understand what you want in the end. If you have list x =  ["user A", "user B", "user C"]; and you want to know if user A is among them, you can get that information by asking

if (~llListFindList(x,"user A") )
{
    llSay(0,"I found user A");
}

If you are hoping for other information from the script, explain.

  • Thanks 1
  • Confused 1

Share this post


Link to post
Share on other sites

Let me explain better.  I need to know which avatar and index was found in my list, like it's gonna be a big list with 50 usernames, llGetAgentList will get all avatars keys in the sim right? So if it finds 1 or more usernames/keys which are in my list, it must return the username from the respective index which was found in my list, so i can know which avatar was found among the others. Get it?

Share this post


Link to post
Share on other sites

@teresasama  Take a look at the userfunction ListXandY in the wiki:

Quote

This function examines two lists, and returns a new list composed of the elements that both lists have in common.

Sounds like what you need.

ETA:   I would, though, make one small but important alteration to that example.  

Where it says 

for (x = 0; x < llGetListLength(ly); x++) {

I would put 

integer n = llGetListLength(ly);
for (x = 0; x < n; x++) {

The reason is that the length of ly isn't going to change while the script is running through the loop checking its members, so it's a waste of resources (and it slows down the script) to keep on counting the number of items in list y every time you check an item from list x against it.

Edited by Innula Zenovka
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
16 minutes ago, Innula Zenovka said:

@teresasama  Take a look at the userfunction ListXandY in the wiki:

Sounds like what you need.

ETA:   I would, though, make one small but important alteration to that example.  

Where it says 


for (x = 0; x < llGetListLength(ly); x++) {

I would put 


integer n = llGetListLength(ly);
for (x = 0; x < n; x++) {

The reason is that the length of ly isn't going to change while the script is running through the loop checking its members, so it's a waste of resources (and it slows down the script) to keep on counting the number of items in list y every time you check an item from list x against it.

That's what I'm looking for! Thanks Innula Zenovka. Just a final touch to get this done. ListXandY returns me a new list right? I wanna get the first index with the avatar username/key of that list. How to get like the first avatar/key from a list? For example if there're 10 usernames in common, I just want the first username no matter how it is sorted by. So I need to get the first index + username from that list.

Share this post


Link to post
Share on other sites

The first element in any list is always element 0.  So,  string strName = llList2String(my_list_of_names,0);

  • Thanks 1

Share this post


Link to post
Share on other sites

@Rolig Loon

1 hour ago, Rolig Loon said:

The first element in any list is always element 0.  So,  string strName = llList2String(my_list_of_names,0);

Thanks Rolig LoonI'm gonna use llKey2Name(llList2Key(my_list, 0)); so I can get the first element which is a key then convert it to a username.

Edited by teresasama

Share this post


Link to post
Share on other sites

If you want the username it's llGetUsername, not llKey2Name.   llGetUsername will return "teresasama" and  "Innula.zenovka".   llKey2Name will return "teresasama resident" or "Innula Zenovka".

 

  • Thanks 1

Share this post


Link to post
Share on other sites

@Innula Zenovka

13 minutes ago, Innula Zenovka said:

If you want the username it's llGetUsername, not llKey2Name.   llGetUsername will return "teresasama" and  "Innula.zenovka".   llKey2Name will return "teresasama resident" or "Innula Zenovka".

 

I was about to make a method to strip the "Resident" out of it, I'm glad you told me about the llGetUsername, thanks a lot Innula Zenovka.

Share this post


Link to post
Share on other sites

Well, for completeness, you can also request llGetDisplayName(). Which one of the functions you use depends on exactly what you need the name for.  (Also, there are the functions llRequestUsername() and llRequestDisplayName(), which you would need to use if the person you are considering is not in the same region.)  B|

  • Like 2

Share this post


Link to post
Share on other sites

@Innula Zenovka

@Rolig Loon

This code compiles but for some reason it doesn't work. The avatar keys from my_list they were present in the same sim, so I expected a message coming from llOwnerSay() but nothing happened.

list my_list = ["43a2cd19-eb07-47a6-b1c3-94ea7924e4f7", "369fac38-c0e6-4c65-b7ca-ff6da91c3d94"];

list ListXandY(list lx, list ly) { // return a list of elements common to both lists
    list lz = []; integer x; integer n = llGetListLength(ly);
    for (x = 0; x < n; x++) {
        if (~llListFindList(lx,llList2List(ly,x,x))) {
            lz = lz + llList2List(ly,x,x);
        }
        else {
            ;
        }
    }
    return lz;
}

default
{
    touch_start(integer total_number)
    {
        list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []);
        list result = ListXandY(avatarsInRegion, my_list);
        llOwnerSay(llGetUsername(llList2Key(result, 0)));
    }
}

 

Share this post


Link to post
Share on other sites

anyhoo, this seems to be workin for me?

( my key is the one ... 06451596-818c-4975-8bc0-058ab2fe8274)

list my_list = 
[
   "43a2cd19-eb07-47a6-b1c3-94ea7924e4f7",
   "369fac38-c0e6-4c65-b7ca-ff6da91c3d94",
   "06451596-818c-4975-8bc0-058ab2fe8274", // ME
   "be7f208e-a4ac-4073-b4eb-277d8581b13e"
];

list ListXandY(list myList, list scanList )
 {  // return a list of elements common to both lists
    list lz = [];
    integer x;
    integer n = llGetListLength( scanList );
    for (x = 0; x < n; x++)
    {
        if (~llListFindList( myList, llList2List( scanList, x, x)))
        {   lz += llList2List( scanList, x, x);           
        }       
    }   
    return lz;    
}

default
{
    touch_start(integer total_number)                              // used "scan" to test
    {   list scan = [ "369fac38-c0e6-4c65-b7ca-ff6da91c3d94",
                      "06451596-818c-4975-8bc0-058ab2fe8274",      // ME
                      "be7f208e-a4ac-4073-b4eb-277d8581b13e"];
        list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []);
        list result = ListXandY(  my_list, scan );                // REPLACE scan WITH  avatarsInRegion
        
        list names ;
        integer y;
        for(; y < llGetListLength(result) ; ++y)
        {  key currKEY =  llList2Key(result,y);
           names +=  llGetUsername( currKEY ) ;
        }
        
        string tmp = llDumpList2String( names, "\n");                          
        llOwnerSay( "\nFound: \n" + tmp );
    }
}

 

 

Edited by Xiija

Share this post


Link to post
Share on other sites
28 minutes ago, Xiija said:

anyhoo, this seems to be workin for me?

( my key is the one ... 06451596-818c-4975-8bc0-058ab2fe8274)


list my_list = 
[
   "43a2cd19-eb07-47a6-b1c3-94ea7924e4f7",
   "369fac38-c0e6-4c65-b7ca-ff6da91c3d94",
   "06451596-818c-4975-8bc0-058ab2fe8274", // ME
   "be7f208e-a4ac-4073-b4eb-277d8581b13e"
];

list ListXandY(list myList, list scanList )
 {  // return a list of elements common to both lists
    list lz = [];
    integer x;
    integer n = llGetListLength( scanList );
    for (x = 0; x < n; x++)
    {
        if (~llListFindList( myList, llList2List( scanList, x, x)))
        {   lz += llList2List( scanList, x, x);           
        }       
    }   
    return lz;    
}

default
{
    touch_start(integer total_number)                              // used "scan" to test
    {   list scan = [ "369fac38-c0e6-4c65-b7ca-ff6da91c3d94",
                      "06451596-818c-4975-8bc0-058ab2fe8274",      // ME
                      "be7f208e-a4ac-4073-b4eb-277d8581b13e"];
        list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []);
        list result = ListXandY(  my_list, scan );                // REPLACE scan WITH  avatarsInRegion
        
        list names ;
        integer y;
        for(; y < llGetListLength(result) ; ++y)
        {  key currKEY =  llList2Key(result,y);
           names +=  llGetUsername( currKEY ) ;
        }
        
        string tmp = llDumpList2String( names, "\n");                          
        llOwnerSay( "\nFound: \n" + tmp );
    }
}

 

 

Whoo-Hoo, Free Keys!!

D162B9F8-C6EA-4390-9AD7-576C380043EE.jpeg

Share this post


Link to post
Share on other sites

@Xiija

It's not working with llGetAgentList(). Well looks like it's complex, you can try this code in world it won't work, but if you're gonna try it don't forget to change the keys for the avatar keys in the same region you're in.

list my_list = 
[
"43a2cd19-eb07-47a6-b1c3-94ea7924e4f7",
"7a6b9c04-b610-4017-9982-80962eda2619"
];

list ListXandY(list myList, list scanList )
 {  // return a list of elements common to both lists
    list lz = [];
    integer x;
    integer n = llGetListLength( scanList );
    for (x = 0; x < n; x++)
    {
        if (~llListFindList( myList, llList2List( scanList, x, x)))
        {   lz += llList2List( scanList, x, x);           
        }       
    }   
    return lz;    
}

default
{
    touch_start(integer total_number)
    {
        list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []);
        list result = ListXandY(my_list, avatarsInRegion);
        
        list names;
        integer y;
        for(; y < llGetListLength(result) ; ++y)
        {  key currKEY =  llList2Key(result,y);
           names +=  llGetUsername( currKEY );
        }
        
        string tmp = llDumpList2String( names, "\n");                          
        llOwnerSay( "\nFound: \n" + tmp );
    }
}

 

Share this post


Link to post
Share on other sites

I suggest that you say the result of llGetAgentList to chat so you can see if it is getting the info or not.

After the call to llGetAgentList, add this line to debug it:

llOwnerSay(“List result=“ + llList2CSV(result));

This will show you what is in the list after llGetAgentList.

Also, in your touch_start event I noticed you are not initializing y to zero.

 

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Love Zhaoying said:

Also, in your touch_start event I noticed you are not initializing y to zero.

No need.  The variable y is local to touch_start, so it's a brand new variable each time execution enters that event, automatically set = 0.

  • Like 1

Share this post


Link to post
Share on other sites
4 minutes ago, Rolig Loon said:

No need.  The variable y is local to touch_start, so it's a brand new variable each time execution enters that event, automatically set = 0.

C’mon, at least agree it’s a bad habit!

5DF80C55-5237-46A1-9C45-1AACD22F7120.jpeg

Share this post


Link to post
Share on other sites

Nah.  Not in LSL.  In fact, it takes more memory to deliberately initialize a variable like that. It's redundant, unless you are dealing with global variables.

  • Like 1

Share this post


Link to post
Share on other sites

It's the old ...list functions don't like Humans ( or other lists )... trick!

changed the string stuff in the.... 'for' statement in the user function

 

.



list my_list = 
[
"43a2cd19-eb07-47a6-b1c3-94ea7924e4f7",
"7a6b9c04-b610-4017-9982-80962eda2619",
"06451596-818c-4975-8bc0-058ab2fe8274" // Xiija
];

list ListXandY(list myList, list scanList )
 {  list lz = [];
    integer x;
    integer n = llGetListLength( scanList );
    for (x = 0; x < n; x++)
    {   string new =  llList2String(scanList, x); 
       if (~llListFindList( myList,[new] )   )
        {   string avi = llList2String( llList2List( scanList, x, x) , 0 ); 
            lz += avi;          
        }       
    }   
    return lz;    
}

default
{
    touch_start(integer total_number)
    {
        list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []);
        list result = ListXandY(my_list, avatarsInRegion);
        
        list names;
        integer y;
        for(; y < llGetListLength(result) ; ++y)
        {  key currKEY =  llList2Key(result,y);
           names +=  llGetUsername( currKEY );
        }
        if( names != [] )
        {  string tmp = llDumpList2String( names, "\n");                          
           llOwnerSay( "\nAvatar Found: \n" + tmp );
        }
        else
           llOwnerSay( "\nNO Avatars Found" );
    }
}

 

Edited by Xiija
  • Thanks 1

Share this post


Link to post
Share on other sites

@Xiija

1 hour ago, Xiija said:

It's the old ...list functions don't like Humans ( or other lists )... trick!

changed the string stuff in the.... 'for' statement in the user function

 

.




list my_list = 
[
"43a2cd19-eb07-47a6-b1c3-94ea7924e4f7",
"7a6b9c04-b610-4017-9982-80962eda2619",
"06451596-818c-4975-8bc0-058ab2fe8274" // Xiija
];

list ListXandY(list myList, list scanList )
 {  list lz = [];
    integer x;
    integer n = llGetListLength( scanList );
    for (x = 0; x < n; x++)
    {   string new =  llList2String(scanList, x); 
       if (~llListFindList( myList,[new] )   )
        {   string avi = llList2String( llList2List( scanList, x, x) , 0 ); 
            lz += avi;          
        }       
    }   
    return lz;    
}

default
{
    touch_start(integer total_number)
    {
        list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []);
        list result = ListXandY(my_list, avatarsInRegion);
        
        list names;
        integer y;
        for(; y < llGetListLength(result) ; ++y)
        {  key currKEY =  llList2Key(result,y);
           names +=  llGetUsername( currKEY );
        }
        if( names != [] )
        {  string tmp = llDumpList2String( names, "\n");                          
           llOwnerSay( "\nAvatar Found: \n" + tmp );
        }
        else
           llOwnerSay( "\nNO Avatars Found" );
    }
}

 

Thank you very much Xiijaeverything is working as intended.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...