Jump to content
Sign in to follow this  
dalocogamer

Self Teaching LSL List

Recommended Posts

I am going through the LSL List wiki to learn to use Lists. I am trying to compare two list and get a resault from it. My script below keeps coming up "its something" when the lists are different from each other. I'm trying to get it to say FALSE aks "its something else". Am I comparing the type of list? I tried inputing "a", "b", "c" in NewList and still get the resault "its something". 

 

list MyList = [1, 2,3];
list NewList = [5, 6, 7];
default
{
touch_start(integer total_number)
{

// llOwnerSay( (string) MyList ); // outcome: abc123.140000<0.000000, 0.000000, 0.000000>
if ( MyList == NewList)
{
llOwnerSay("its something");
}
else
{
llOwnerSay("its something else");
}
}
}

 

EDIT

Ok I just found out if I set MyList as list MyList = []; I can get the message "its something else". I thought when I compared the two lists I was comparing the content inside. My new question is how do I compare the content inside my two lists? 

Share this post


Link to post
Share on other sites

The comparison operator when used on lists simply tests the length of each list, not the contents, so two lists [1,2,3] and ["A","B","C"] will show as being equal. [1,2] and ["a","b","c"] will show as different.

If you want to check if two lists are different, the first thing to do is compare them as you have just done, and if the result comes back as FALSE, it shows the lists have different lengths, and are therefore not the same. But when it returns TRUE, you then need to step through the lists element by element, comparing them and seeing of they differ.  Or.... http://wiki.secondlife.com/wiki/ListCompare in the wiki under extended operations is a very good example of what is at first non-obvious, and will save you  lot of time which going through the list element by element, finding the element type, seeing of the other list has the same element type, then comparing values if they are the same type would otherwise involve.

Share this post


Link to post
Share on other sites

Thank you for your resonse and guidance to another section I didn't see. I am going to try and see if I can do this. I'll post up my resault here in a bit.

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...