Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Reading multipel values from a string?

Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
08-05-2004 19:01
What is the best way to reading multiple values from a string?
I'm working on a script, and and I'm reading a string that contains multiple values. The string could contain multiple values. And those values can be a mix of string values and vector values.

I chose to use llParseString2List(string, [";",":"], []) to break up the string into a list. I figured I could then read the list one line at a time. And interrupt those lines to get each value.
But I can't seem to use any of the built in command to read an items from the list. Let alone assign other variables their values from the list. I tried to use llList2String or llList2vector. Both of the command cause compiling errors. ie string word = llListing2string(list); == error :\

I was wondering if any one with experience with retrieving multiple values of different types from a string. Or retrieving values from a list. Any one want to share their wisdom? please?

Also is their a specific way I should be writing a vector value in a string? ie <0.0,0.0,0.0>, "0.0,0.0,0.0", "0.0 0.0 0.0" ?
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
08-05-2004 19:52
Use llList2String -- it works, and it easy enough.

The problem is likely that you're not casting to the correct type. Once you have a string containing a vector, (vector)string_name is what you want to convert it to a vector.

Yes, <1,325.260,20.0> is the correct syntax for a vector. Spaces are not necessary, but will not break things if they're in there. You need the commas and angle brackets though.

Now, when you say "string word = llListing2string(list); == error", I assume you're using the "C syntax as ironic grammar replacement" sense, and that you're not actually trying to compare variables or something, right?

Also, are you sure you have "llListing2string" and not "llList2String"? That might work better. :)

Posting the section of code you're having trouble with always helps.
_____________________
Need scripting help? Visit the LSL Wiki!
Omega Point - Catherine Omega's Blog
McWheelie Baldwin
Registered User
Join date: 9 Apr 2004
Posts: 154
08-06-2004 12:35
Also, llList2String() takes two parameters, the list and the index of the item in the list to return as a string. The index is 0 based, so for instance to get the third item from the example list below you would use the following call:

list sample = ["apple", "banana", "orange", "pear"];
string fruit = llList2String(sample, 2);


fruit will then be set to orange.
Hope this helps you out.

*edited* for typos
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
08-07-2004 15:50
this is a snippet of the code I'm using

//Peramiters. The Function peramiters a list from full name.
list permaiters = ["rave","o",<01.0,1.0,1.0>,"a",<0.2,1.0,0.1>,"s","dance"];
//active counter part to defolts sitting. These may change with each sit.
// Full_Animation_Name = ShortName;o:offSet;a:angle;s:sitname
string ShortName = "shorty";
vector offSet;
vector angle;
string sitName = "get shorty";




//read the a list, if a line matches a defined string. it will use the next line t asine a value .
// I chose short names because of the limited room of the name field
// note: pre loop ShortName , the first line of list
// note: o:<0.0,0.0,0.0001> = offSet:vector
// note: a:<0.0,0.0,0.,> = angle:vector
// note: s:"sitHere" = sitName:string
list2Values(list inList, integer ListLength)
{
integer counter = 0;
ShortName = llList2String(inList, counter);
llSay(0, (string)counter + " : " + ShortName);
for(counter = 1; counter < ListLength; counter++)
{
string prefix = llList2String(inList, counter);
llSay(0, (string)counter + " : " + llList2String(inList, counter) + " : " + prefix);
counter++;
if (counter <= ListLength)
{
if(prefix == "o";)
{
offSet = (vector)llList2String(inList, counter);
llSay(0, (string)counter + " : " + llList2String(inList, counter) + " : " + (string)offSet);
}
else if (prefix = "a";)
{
angle = (vector)llList2String(inList, counter);
llSay(0, (string)counter + " : " + llList2String(inList, counter) + " : " +(string)angle);
}
else if (prefix = "s";)
{
sitName = llList2String(inList, counter);
llSay(0, (string)counter + " : " + llList2String(inList, counter) + " : " + sitName);
}
}
}
}




default
{

state_entry()
{

}

touch_start(integer total_number)
{
list2Values(permaiters,6);

llSay(0, "Final Resolts : " + ShortName + " " + (string)offSet + " " + (string)angle + " " + sitName);
}
}

and this is the out put it produces.

Object: 0 : rave
Object: 1 : o : o
Object: 2 : <1.000000, 1.000000, 1.000000> : <1.00000, 1.00000, 1.00000>
Object: 3 : a : a
Object: 4 : <0.200000, 1.000000, 0.100000> : <0.20000, 1.00000, 0.10000>
Object: 5 : s : s
Object: 6 : dance : <0.00000, 0.00000, 0.00000>
Object: Final Resolts : rave <1.00000, 1.00000, 1.00000> <0.00000, 0.00000, 0.00000> get shorty

I see two problems with the output. line 6 says s is getting the data dance, but it's ending up with the value of a vector, and then the final results shows that and s do not receive the right value.

What's wrong, and why is it reporting invalid resolts?
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
08-08-2004 01:32
no one?
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
08-08-2004 03:15
You're doing this:

CODE
else if (prefix = "a")
{
angle = (vector)llList2String(inList, counter);
llSay(0, (string)counter + " : " + llList2String(inList, counter) + " : " +(string)angle);
}


You need to be doing this:
CODE
else if (prefix == "a")


"=" sets the first variable to the value of the second one.

"==" checks if both variables are the same.
_____________________
Need scripting help? Visit the LSL Wiki!
Omega Point - Catherine Omega's Blog
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
08-08-2004 13:44
oh man i'm making newbie mistakes. Thank you very much :D