Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

string to vector or integer???

CaptnPower Codesmith
Second Life Resident
Join date: 9 Nov 2004
Posts: 58
01-04-2005 17:54
ok iv been doing stuff whit link message and lllisten
but i get to a point were i would like to just be able to do "color 0,0,1" instead of color blue and converting it in the script

i know how to get a said char in the message and i know how to store it in a string
but i cant seam to be able to use the string in color vector
can any one help me here
Pete Fats
Geek
Join date: 18 Apr 2003
Posts: 648
01-04-2005 18:32
If you have 3 seperate strings:

vector color = <;(float)string1, (float)string2, (float)string3>;

If you have a string like this:

<0, 0, 0> then vector color = (vector)string;
_____________________
Tony Tigereye
Registered User
Join date: 4 Sep 2003
Posts: 165
01-04-2005 18:53
Pete's right. Or:

user could say "color <1,1,1>"

CODE
if ( llGetSubString(message,0,4) == "color" )
{
string sColor = llGetSubString(message,6,-1);
vector vColor = (vector)sColor;
llSetColor(vColor, ALL_SIDES);
}
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
01-04-2005 23:44
Or:

user could say "color 1,1,1"

CODE
if ( llGetSubString(message,0,5) == "color " )
{
vector vColor = (vector)("<"+llDeleteSubString(message,0,5)+">");
llSetColor(vColor, ALL_SIDES);
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Hiro Pendragon
bye bye f0rums!
Join date: 22 Jan 2004
Posts: 5,905
01-05-2005 01:04
I like using standard character delineators (like "," or "|" or ":";)

So using your example:
"color 0,0,1"
let's say this is your entire message, and you save it in your listen as a string named msg

list newlist = llParseString2List(msg,[],[" ",","]);

newlist would be = ["color"," ","0", ",", "0", ",", "1"]

or if you changed your input to "color,0,0,1" you can now parse just on the comma and throw it away:
list newlist = llParseString2List(msg,[","],[]);

newlist would be = ["color", "0", "0", "1"];

Also what's easy enough to do is have a 0-255 input, then simply divide each input by 255 before you use the color. In this way you can have colors standard to how prims are assigned color.

You can also double parse a list on your original input:
string msg = "color 0,0,1";

list newlist = llParseString2List(llList2String( llParseString2List(msg,[" "],[]),1) );

would produce newlist = ["0","0","1"];

Broken down - first the message is parsed by space delineator, leaving two substrings "color" and "0,0,1" in a list. Then the second string in this list is parsed by commas, producing the final list.

Finally, no matter which way you choose, you access the member in the list like - integer color = llList2Integer(newlist,1);
this would grab the second item in newlist as an integer

http://secondlife.com/badgeo/wakka.php?wakka=llParseString2List
http://secondlife.com/badgeo/wakka.php?wakka=llList2String
http://secondlife.com/badgeo/wakka.php?wakka=lists
_____________________
Hiro Pendragon
------------------
http://www.involve3d.com - Involve - Metaverse / Emerging Media Studio

Visit my SL blog: http://secondtense.blogspot.com