llList2Vector woes
|
|
Allan Beltran
Registered User
Join date: 2 Dec 2006
Posts: 52
|
01-05-2007 00:57
Okay, after banging my head against the wall, I finally thought I narrowed the problem down and adjusted my code accordingly. However, I would seem that llList2Vector and llList2Rot are broken. //Parse message into message and user id msg_list = llParseString2List(message,[","],[]); llSay(0,(string)msg_list);//Reports that all data has been properly passed msg_foundation_loc = (vector)llList2String(msg_list,2); msg_foundation_rot = (rotation)llList2Rot(msg_list,3);
llSay(0,"Foundation loc: " + (string)msg_foundation_loc); //still <0,0,0> llSay(0,"Foundation rot: " + (string)msg_foundation_rot); //still <0,0,0,1> Elements 0 and 1 are irrelevant for this post, so I left them out. It's just a key value and a string message. Any new insight into this strange behavior?
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
01-05-2007 01:12
How are you packing your data into the input string? a vector will be converted into a string as "<x,y,z>" Your code is then stripping / parsing this into a list as
element 0 <x element 1 y element 2 z>
Dumping out each list element as a string using llSay should confirm this
|
|
Allan Beltran
Registered User
Join date: 2 Dec 2006
Posts: 52
|
01-05-2007 01:23
From: Newgate Ludd How are you packing your data into the input string? a vector will be converted into a string as "<x,y,z>" Your code is then stripping / parsing this into a list as
element 0 <x element 1 y element 2 z>
Dumping out each list element as a string using llSay should confirm this Ah, I see, that makes sense. How would I parse the string as a whole vector? Or am I stuck with assiging the values to the elements of my vector, msg_foundation_loc?
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
01-05-2007 01:32
From: Allan Beltran Ah, I see, that makes sense. How would I parse the string as a whole vector? Or am I stuck with assiging the values to the elements of my vector, msg_foundation_loc? Easy, dont use comma's as seperators, use pipes or some other delimiter.
|
|
Allan Beltran
Registered User
Join date: 2 Dec 2006
Posts: 52
|
01-05-2007 01:38
From: Newgate Ludd Easy, dont use comma's as seperators, use pipes or some other delimiter. lol, thanks, I was about to nuke it with msg_list = llParseString2List(message,[",","<",">"],[]); And then load each element separately. Thanks for the help. Semicolons seem in order for this.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
01-05-2007 01:52
From: Allan Beltran lol, thanks, I was about to nuke it with msg_list = llParseString2List(message,[",","<",">"],[]); And then load each element separately. Thanks for the help. Semicolons seem in order for this. Would have worked just as well.
|
|
Allan Beltran
Registered User
Join date: 2 Dec 2006
Posts: 52
|
01-05-2007 02:27
Well, I thought that would be the end of it and it seemed like it at first. Unfortunately, the rotation still isn't coming out right. //Parse message into message and user id msg_list = llParseString2List(message,[";"],[]); //using ";" now llSay(0,message); //Reports that all data has been //properly delimitted with semi-colon's
llSay(0,(string)msg_list); //Reports that all data has been //properly passed
msg_foundation_loc = (vector)llList2String(msg_list,2); msg_foundation_rot = (rotation)llList2Rot(msg_list,3);
llSay(0,"Foundation loc: " + (string)msg_foundation_loc); //good to go now llSay(0,"Foundation rot: " + (string)msg_foundation_rot); //still <0,0,0,1>
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
01-05-2007 02:33
Can you post the data in to have a look at? llOwnerSay("received [" + message + "]"); llOwnerSay("Item 2 Should be a vector [" + llList2String(msg_list,2); + "]"); llOwnerSay("Item 3 Should be a rotation[" + llList2String(msg_list,3); + "]");
|
|
Allan Beltran
Registered User
Join date: 2 Dec 2006
Posts: 52
|
01-05-2007 02:44
AB Racing - Garage: received [34dc19f8-3f9a-45b0-b03f-cadd38ca8150;DOCK HERE!;<109.04449, 220.53587, 96.42538>;<0.00000, 0.00000, -0.37461, 0.92718>] AB Racing - Garage: Item 2 Should be a vector [<109.04449, 220.53587, 96.42538>] AB Racing - Garage: Item 3 Should be a rotation[<0.00000, 0.00000, -0.37461, 0.92718>]
As you can see, the vector and rotation are being passed.
And here it is after llList2Rot.
AB Racing - Garage: Foundation rotation after (rotation)llList2Rot(msg_list,3); <0.00000, 0.00000, 0.00000, 1.00000>
|
|
Damanios Thetan
looking in
Join date: 6 Mar 2004
Posts: 992
|
01-05-2007 03:34
Try using: rot = (rotation) llList2String(msg_list,3);
|
|
Allan Beltran
Registered User
Join date: 2 Dec 2006
Posts: 52
|
01-05-2007 05:36
From: Damanios Thetan Try using: rot = (rotation) llList2String(msg_list,3); Slaps self in the fore head. Well, I've already done it the element by element way, but I may just switch it back because it just looks cleaner, IMO. Thanks.
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
01-05-2007 14:09
llList2Vector and llList2Rot have known limitations in that they do not convert data from string representations in the list, unlike llList2Integer and llList2Float.
IE, if you had the list:
list TestData = [<1.0,2.0,3.0>,"<1.0,2.0,3.0>"];
llList2Vector(TestData,0) would give you the correct vector <1.0,2.0,3.0>,
but
llList2Vector(TestData,1) would give you the NULL_VECTOR <0.0,0.0,0.0>,
because it doesn't convert from string representation. As a result you have to use explicit casts against reading the elements as strings (ie, (vector)llList2String(TestData,1) ) to get the correct values all the time.
Of course, if you can GUARANTEE that the data will always be put into the list as a vector or a rotation numeric type, then you can use llList2Vector and llList2Rot without fear.
|
|
Vilkacis Mason
Registered User
Join date: 30 Aug 2005
Posts: 49
|
01-05-2007 15:08
Personally I use CSV (Comma Seperated Values) for this sort of thing. llCSV2List() and llList2CSV() are great functions. You can take the list you get back from llGetPrimitiveParams() and convert it into a CSV (0, 0, <1.0, 1.0, 1.0>  and it's actually quite smart with it. For instance, assume the following list: 0, 0, <1.0, 1.0, 1.0> If you just divide it up by commas, you would get 5 elements (and junk triangle brackets). But CSV is smart. A vector or rotation returns as ONE element. So you would only have 3 elements in CSV, making it very easy to recall stored vectors and rotations to a string. There's more information in the Wiki. I've been using CSV in tandum with llGetPrimiteParams() with great results for awhile now. EDIT: Also, TYPE-CAST, TYPE-CAST, TYPE-CAST! I have learned that SL knows nothing about anything. I use (string)llList2String() or (vector)llList2String() in almost all instances. Even when I use llList2Integer, I typecast it to an (integer) as well just to be safe. I've had problems in the past.
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
01-05-2007 15:26
Well, there is certainly nothing wrong to being safe (except adding overhead), but in my almost 10 months of scripting in SL, I've never had any problems with implicit casting, except with those two functions. In contrast, I've never used the CSV functions in anything I have written (preferring the Parse and Dump functions in their stead), but that certainly doesn't mean they aren't useful functions. 
|