Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Converting a string to vector?

Gwylym Loon
Registered User
Join date: 6 Jun 2007
Posts: 81
05-19-2008 16:17
I'm trying to read a notecard with vectors and rotations to set where an object is rezzed.

For example:

<0,0,1.2>/<90.0,0.0,270.0>/texturename

Where the fist item is an offset, the second is a rotation and the third is a texture name. I tried using llParseString2List and it did not work. I need to break the string on the /'s and build a list from the pieces with the first two entries being vectors. Any easy way to do this? Or any easy way to take a string and produce a vector?
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
05-19-2008 16:33
From: Gwylym Loon
I'm trying to read a notecard with vectors and rotations to set where an object is rezzed.

For example:

<0,0,1.2>/<90.0,0.0,270.0>/texturename

Where the fist item is an offset, the second is a rotation and the third is a texture name. I tried using llParseString2List and it did not work. I need to break the string on the /'s and build a list from the pieces with the first two entries being vectors. Any easy way to do this? Or any easy way to take a string and produce a vector?


I have noticed some flakiness with llList2Vector recently. Frankly I don't trust the llList2___ functions if I can help it. I use the simple "list 2 string" and then pull that out and cast it to what I want.

Also "/" and particularly "\" can make for confusing weirdness, so ditch them.. let's use "|".
CODE

input = "<0,0,1.2>|<90.0,0.0,270.0>|texturename";
list commands = llParseString2List(input, ["|"], []);
vector offset = (vector)llList2String(commands, 0);
vector rotate = (vector)llList2String(commands, 1);
key texture = (key)llList2String(commands, 2); // assuming it's a key, and not a inventory name
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
05-19-2008 16:36
(Redundant double-post. With error, even.)
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
05-19-2008 16:42
Oops. Simul-post. Anyway, you could also use commas. llCSV2List() automatically handles the difference between separators inside and outside of vector/rotation brackets. As mentioned by Winter, llList2Vector() and llList2Rotation() do not work on list elements that are strings. The other ones (llList2Integer(), llList2Float(), etc.) happen to, but I usually use the correct extraction method myself (the one that matches the actual type of element in the list) when known.
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
05-19-2008 16:42
From: Hewee Zetkin
CODE

string input = "<0,0,1.2>/<90.0,0.0,270.0>/texturename";


string input = "< 0 , 0 , 1.2 > / < 90.0 , 0.0 , 270.0 > / texturename";

cell 2 in the list is a euler vector... in degrees. not a quaternion in radians. "vector" is appropriate here, not "rotation" :o
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
05-19-2008 16:45
From: Winter Ventura
string input = "< 0 , 0 , 1.2 > / < 90.0 , 0.0 , 270.0 > / texturename";

cell 2 in the list is a euler vector... in degrees. not a quaternion in radians. "vector" is appropriate here, not "rotation"

Oh! Oops. I breezed right over that. Thank you. I'll correct. :-)
Gwylym Loon
Registered User
Join date: 6 Jun 2007
Posts: 81
05-19-2008 16:45
From: Winter Ventura
string input = "< 0 , 0 , 1.2 > / < 90.0 , 0.0 , 270.0 > / texturename";

cell 2 in the list is a euler vector... in degrees. not a quaternion in radians. "vector" is appropriate here, not "rotation"



yes, correct. Its been a long Monday.

Thanks to Everyone who responded!

p.s. I tried the csv2list function and had problems with that but will go back to it and use strings and type casting.
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
05-19-2008 16:48
From: Hewee Zetkin
Oh! Oops. I breezed right over that. Thank you. I'll correct. :-)


yeah well I was casting the texture to a key and trying to store it in a vector... so I had a typo too. Or is that a code-o? Fixed mine too.
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura