Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

string to vector?

Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
02-25-2007 15:48
Hello again.
I'm noticing one major weakness in all of the methods in which to convey information from one object to another - No vectors can be passed between them. llListen picks up strings, llMessageLinked picks up strings, integers and keys... But no vectors. So, the only possible way I can figure to pass a vector to objects would be to send it as a string, then have it convert it into a vector - But I can't figure out how to do that. Any suggestions?
Edit: Clarification - The string I'm passing is llGetColor in a string through a llMessageLinked.
Ged Larsen
thwarted by quaternions
Join date: 4 Dec 2006
Posts: 294
02-25-2007 17:00
From: Hg Beeks
Hello again.
I'm noticing one major weakness in all of the methods in which to convey information from one object to another - No vectors can be passed between them. llListen picks up strings, llMessageLinked picks up strings, integers and keys... But no vectors. So, the only possible way I can figure to pass a vector to objects would be to send it as a string, then have it convert it into a vector - But I can't figure out how to do that. Any suggestions?
Edit: Clarification - The string I'm passing is llGetColor in a string through a llMessageLinked.


You need to typecast. For example:

CODE

string s = "<1.0, 2.0, 3.0>"; // s is a string
vector v = (vector)s; // v is a vector
llOwnerSay("And then back to a string again: "+(string)v); // cast v from vector back to string, to include in a Say
_____________________
- LoopRez, flexi prim skirt generating tool
- LinkRez, a necklace chain generator
Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
02-25-2007 17:37
I'm starting with a vector, converting it to string, then trying to convert it back to vector, not to string. I'm trying to send the color information from one prim to its children, so that they can match the color.

llMessageLinked(-1, 0, (string)llGetColor(ALL_SIDES), "";);

sends the vector the same as you show it - <0.7832, 0.80278, 0.5978>.
However, when the children try to use this information using

llSetColor((vector)text, ALL_SIDES);

they turn full black.
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
02-25-2007 19:30
Just for grins, do an llOwnerSay of each string along the way . . . see if it changes; especially see if the children hear what you think they hear.

Also, you use llGetColor(ALL_SIDES). Is the color the same on all sides? Would it be any better to just get the color from one side?

Otherwise, this technique of typecasting should work. I've used it to transmit via link messages, and it seems to work fine.

Baron H.
Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
02-25-2007 20:05
I actually tested that first; It spits back the same string every time. and yes, the color is the same on all sides. I'll post the code when I get home for further inspection.
AJ DaSilva
woz ere
Join date: 15 Jun 2005
Posts: 1,993
02-25-2007 20:55
I'm working on a project where I send vector data through strings at the moment.

Mostly it works as you'd expect, I have found that parsing a string into a list then pulling the vector directly with llList2Vector(aList,i) doesn't work and you have to use (vector)llList2String(aList,i) instead.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-26-2007 00:46
The casting to string and then back to vector should work fine, its how my own colouring system works.

Script fragment - Sender
CODE

vector vcolour = llList2Vector(lColours, iIndex );
string msg = "COLOUR:" + (string)vcolour;
llShout(ChannelNum,msg);


Script Fragment - Receiver
CODE

listen( integer channel, string name, key id, string message )
{
list lData = llParseString2List(message, [":"], [""]);
string command = llList2String(lData, 0);
string item = llList2String(lData, 1);
integer side = ALL_SIDES;
if("COLOUR" == command)
{
vector clr = (vector)item;
llSetColor(clr,side);
}
}


Although it wont help with your application, I've actually gone away from using vectors to store the colours, just using strings to save on converting from list to vector to string and then back to vector.