Jump to content
Sign in to follow this  
Xed Saunders

list sort

Recommended Posts

i'm going mad with a simple thing, i can't see what i'm doing wrong, i am sorting a list composed by strings.

        list names=["36.321","name2","30.456","name1","30.455","name3","29.452","name4"];
        list sorted=llListSort(names,2,TRUE);
        llSay(0,"output:"+(string)sorted);

this works and produce Object: output:29.452name430.455name330.456name136.321name2

this don't

list newentry=[];
list allbest=[];
default
{
    state_entry()
    {
                llListen(-3500, "", "", ""); 
    }
    listen(integer channel, string name, key id, string listener)
    {
        newentry=newentry+[llParseString2List(listener,[""],[" "])];
        allbest=llListSort([newentry],1,TRUE);
        llSay(0,"output:"+(string)allbest);
    }    
}

produce output:36.234name534.234name132.234name4

is the order i type them in the chat with /-3500 TimeName

can't llistsort be used with a listener?

tia

 

Share this post


Link to post
Share on other sites
Posted (edited)

The second script you've posted will never work: you have lists inside lists:

[llParseString2List(listener,[""],[" "])]
[newentry]

The result of llParseString2List is a list, so putting it inside brackets is putting a list inside a list. And the same applies to newentry.

In the llListSort call you set a stride of 1. I think you mean 2 there.

In the llParseList2String call you don't specify any separators, but you do include a space in the spacers. Separators are discarded, while spacers are included in the list as items in their own right. I think you want them the other way around.

Also, a slightly neater way to see what a list contains is to use the function llList2CSV which separates the list items from each other with commas.

I think the example below might be what you're looking for:

list newentry=[];
list allbest=[];
default
{
    state_entry()
    {
                llListen(-3500, "", "", ""); 
    }
    listen(integer channel, string name, key id, string listener)
    {
        newentry=newentry+llParseString2List(listener,[" "],[]);
        allbest=llListSort(newentry,2,TRUE);
//        llSay(0,"output:"+(string)allbest);
        llOwnerSay ("Output: " + llList2CSV (allbest));
    }    
}

 

 

Edited by KT Kingsley

Share this post


Link to post
Share on other sites

thanks. i'll try iw as i can login, by the way doing a quick copy and paste i've pasted an error in the stride, which is 1, your guess was correct :)

 

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.

Sign in to follow this  

×
×
  • Create New...