Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

ParseString2List problems

Rock Ryder
Registered User
Join date: 6 Oct 2006
Posts: 384
09-22-2007 13:42
Hi guys,

Can anyone tell me how to use the llParseString2List properly, the wiki is pretty deficient in clarity here.

Here is the snippet of code:

coords = "<24,212,34>"; //this actually gets into the script via chat on channel /55

xyz = llParseString2List(coords, [","],["<",">"]);

X = llList2String(xyz,0);
Y = llList2String(xyz,1);
Z = llList2String(xyz,2);

llSay(0, "X = " + X + "; Y = " + Y + "; Z = " + Z);

What I get is:

X = <; Y = 24; Z = 212

when of course what I want is:

X = 24; Y = 212; Z = 34

I realise that the problem is in the separators and spacers declaration, but i have tried a few combinations now with no luck. Any ideaock
Fluf Fredriksson
Registered User
Join date: 8 Feb 2007
Posts: 248
09-22-2007 13:52
Try ...

vector coords=<24,212,34>;
string X=(string)coords.x;
string Y=(string)coords.y;
string Z=(string)coords.z;
llSay(0, "X = " + X + "; Y = " + Y + "; Z = " + Z);

But you might want to convert to integers first to knock the decimal places out?
Rock Ryder
Registered User
Join date: 6 Oct 2006
Posts: 384
09-22-2007 14:01
From: Fluf Fredriksson
Try ...

vector coords=<24,212,34>;
string X=(string)coords.x;
string Y=(string)coords.y;
string Z=(string)coords.z;
llSay(0, "X = " + X + "; Y = " + Y + "; Z = " + Z);

But you might want to convert to integers first to knock the decimal places out?


Hi Fluf, the coordinates come in as a string via a listen event. But your idea can be readily adapted. I can convert the string to a vector first then use your suggestion. So the problem is now solvable.

Thanks a lot

(but I still didn't get to understand the ParseString2List command though :( )

Rock
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
09-22-2007 14:17
When a string in the first list (a "separator";) is encountered, the string is split in two around it and the separator is discarded. When a string in the second list (a "spacer";) is encountered, the string is split in two around it, but the spacer itself is kept as an additional element in the middle.

The result of your
llParseString2List(coords, [","],["<",">"])
is
["<", "24", "212", "34", ">"]
The brackets are kept, and the commas discarded. So the coordinates are elements 1, 2, and 3.

If you swapped the arguments and did
llParseString2List(coords, ["<", ">"], [","])
the result would be:
["24", ",", "212", ",", "34"]
This time the commas are kept, and the brackets are discarded. The coordinates are elements 0, 2, and 4.

Putting them all in the first list discards both the brackets and commas, so
llParseString2List(coords, ["<", ">", ","], [])
gets you:
["24", "212", "34"]
With the coordinates as 0, 1, and 2, like you were expecting.
Fluf Fredriksson
Registered User
Join date: 8 Feb 2007
Posts: 248
09-22-2007 14:46
From: Rock Ryder
Hi Fluf, the coordinates come in as a string via a listen event. But your idea can be readily adapted. I can convert the string to a vector first then use your suggestion. So the problem is now solvable.

Thanks a lot

(but I still didn't get to understand the ParseString2List command though :( )

Rock
Ooops. Sorry. Skipped the bit about getting the info via chat! And I see someone else has dealt with the parse side! But anyway you might want to try http://lslwiki.net/lslwiki/wakka.php?wakka=HomePage for your LSL lookups. Might give you more information than you have at the moment.
Rock Ryder
Registered User
Join date: 6 Oct 2006
Posts: 384
09-22-2007 15:47
Wow, what two great replies.

Fluf provided the perfect solution. The coords = (vector)msg instruction solved it easily and simply.

Mazakazu not only gave me the solution to the llParseString2List problem, but the explanation was very enlightening, and I now see how it works.

This forum Rocks,

Rock

PS The script I am working on right now is a suite of sim parcelling tools.