Jump to content

List Length


Pedlar Decosta
 Share

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

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

Recommended Posts

Hi all, I am getting a strange/unexpected result when calling for a list length in one of my scripts.

Basically I am testing it using -  llOwnerSay("list is "+llList2CSV(accesslist)+" and length is "+(string)llGetListLength(accesslist));

and this is the reply - [19:44] TV - Scripted: list is  and length is 1

so my question is, if it says the list is empty, why is the length saying 1 ?

I thought it was possibly a space but I tested for that with this -

 llOwnerSay("list is this |"+llList2String(accesslist,0)+"|");
 llOwnerSay("2list is this |"+llList2String(accesslist,1)+"|");

and got this -

[20:02] TV - Scripted: list is this ||
[20:02] TV - Scripted: 2list is this ||

All I wanted to do was eliminate the comma after the owner name (not on the list but added first in the feedback) if no one was on the list...

I have other scripts where I have succeeded in changing the output if the answer was singular or multiple, however again... I am trying to identify why there's a problem in the first place.

In case it is relevant, this is how the list is formed -

            string message2 = llToLower(message);
            accesslistfilter3 = [];
            accesslistfilter3 += llCSV2List(message2);
            accesslistfilter2 = ListItemDelete(accesslistfilter3, "ac");
            accesslistfilter = ListXorY(accesslistfilter, accesslistfilter2);
            accesslist = ListXorY(accesslist, accesslistfilter);
            accesslist = ListItemDelete(accesslist, "");

(This is probably ugly coding to you guys, but it seems to work nicely for me).

Edited by Pedlar Decosta
Link to comment
Share on other sites

if you copied this line directly from chat: [19:44] TV - Scripted: list is  and length is 1

then there are 2 spaces between "is" and "and". Which indicates that the list has an empty element in it.  Which makes the length return of 1 from llGetListLength()  accurate

  • Like 1
Link to comment
Share on other sites

If you just want to keep from having a comma print out in chat if there's only one element in your list, try

default
{
    touch_start(integer total_number)
    {
        list a = ["My list"];
        llSay(0, llDumpList2String(a,","));
        a += [ " with a comma in the middle"];
        llSay(0, llDumpList2String(a,","));        
    }
}


 

  • Like 1
Link to comment
Share on other sites

but I added spaces in the feedback to separate the words. Are you sure this is extra after those MollyMews?

i.e  llOwnerSay("list is (space here)"+llList2CSV(accesslist)+" (and here)and length is "+(string)llGetListLength(accesslist));

thanks Rolig, I am always grateful for better ways to write it, but also am curious to why there is a hidden element in the first place.

Link to comment
Share on other sites

18 minutes ago, Pedlar Decosta said:

but I added spaces in the feedback to separate the words. Are you sure this is extra after those MollyMews?

sorry, i wasn't clear in my meaning

what Rolig said. For llGetListLength() to return 1 then there is something in the  first list element, either a empty element or a non-printable character

  • Like 1
Link to comment
Share on other sites

Ok, I have worked out where the problem was. I could not make the hidden element reveal itself though, but at least I know what caused it. I had this -

string accesslist3;

//and-
        if ( name == "name" )
                    {

                        name = (string)value;
                        accesslist2 += [llToLower(value)];
                        accesslist3 = llList2CSV(accesslist2);
                      }

//and then this -

accesslist = llCSV2List(accesslist3);

So I had incorrectly referred to accesslist3 as a list when it was actually a string.

All I had to do to fix it was parse the string and then the accesslist received the correct info and my list was then empty as it should have been.

I hope this helps someone else with similar problems. :)

  • Like 1
Link to comment
Share on other sites

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