Jump to content

Self Teaching LSL List


dalocogamer
 Share

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

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

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? 

Link to comment
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.

Link to comment
Share on other sites

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