Jump to content

llList2Vector returns only ZERO_VECTOR


Handarido Optera
 Share

Recommended Posts

Keep an eye on a possible bug:

When the input  to a list is a string then llList2Integer, llList2Float, and llList2Key work perfectly fine and return the appropriate type. Not llList2Vector:

 

default
{
    touch_start(integer total_number)
    {
        list my_list = [] + "<2.0, 2.0, 2.0>";
        
        vector result = llList2Vector(my_list, 0); 
        llOwnerSay((string)result); // returns ZERO_VECTOR
        result = (vector)llList2String(my_list, 0);
        llOwnerSay((string)result);  // returns <2.00000, 2.00000, 2.00000>
    }
}

 You need to use llList2String and then cast it as a vector.

Link to comment
Share on other sites

Also, although it's not apparently required by the compiler, I have found that it's best to be explicit about adding list elements to lists.  So

glMyList  = glMyList + [<2.0,2.0,2.0>];

or

glMyList += [<2.0,2.0,2.0>];

instead of

glMyList += "<2.0,2.0,2.0>";

If nothing else, that's a reminder that I'm always concatenating like elements. 

 

Link to comment
Share on other sites

You run into a similar version of this "gotcha" when trying to extract vectors and rotations from messages or read them from notecards   Any vector or rotation you send is a string when it arrives, and has to be cast as the appropriate data type before use.    I discovered this the hard way when trying to load a list of colour vectors from a notecard, when I had only recently started scripting, and the frustration and puzzlement is still very vivid.

The same is true of any datatype that's not a string, of course, with the semi-exception of keys, which are a particular type of string.   Sometimes you need to cast and them and sometimes it's not strictly necessary.    However, since I can never remember when you need to and when you don't, I find it far easier and safer always to cast keys as keys.

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...