Stinky Queso
Second Life Resident
Join date: 29 Nov 2004
Posts: 53
|
12-23-2004 15:31
Basically I want to have a script in the parent prim of my object, that sends linkmessages to specific child prims. The child prims then interpret the message and change color accordingly. I really want to set it up so that you can say "color" and then a vector, and the vector will be interpreted as a color. I tried and tried last night, shoving strings into lists and pulling them out as vectors. I tried typecasting strings to vectors, and my string manipulation wasnt flawed. All the vectors ended up <0,0,0>.
Is there a way to convert strings into vectors? Or would I have to pick out the three numbers and assign them floats, which would then be put into vectors?
|
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
|
12-23-2004 15:59
if your trying to asine colors to a set of object in a link set, it would probable be easer to set the color with llSetLinkColor insted of having a script in each and every primtive.
yes you can convert text to vector. It has to formated properly, other wise it will result as <0.0,0.0,0.0>.
string color = "<3.0,4.0,5.0>" (vector) color == <3.0,4.0,5.0> returns true.
--
list colors = ["<3.0,4.0,5.0>"] vector aColor = llList2Vector ( colors, 0 ) aColor == <3.0,4.0,5.0> returns true
--
list colors = ["color<3.0,4.0,5.0>"] vector aColor = llList2Vector ( colors, 0 ) aColor == <3.0,4.0,5.0> returns FALSE
--
list colors = ["color","<3.0,4.0,5.0>"] vector aColor = llList2Vector ( colors, 1 ) aColor == <3.0,4.0,5.0> returns TRUE
--
list colors = ["color"," <3.0,4.0,5.0>"] vector aColor = llList2Vector ( colors, 1 ) aColor == <3.0,4.0,5.0> returns FALSE
--
list colors = ["color"," ","<3.0,4.0,5.0>"] vector aColor = llList2Vector ( colors, 1 ) aColor == <3.0,4.0,5.0> returns FALSE
--
list colors = ["color"," ","<3.0,4.0,5.0>"] vector aColor = llList2Vector ( colors, 2 ) aColor == <3.0,4.0,5.0> returns TRUE
|
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
|
12-23-2004 16:01
I'm not sure what you are doing wrong, but here is some code that I just wrote and tested in game: string sVec = "<1.0, 0.5, 0.75>"; list lVec = [ sVec, sVec ];
default { touch_start(integer total_number) { vector color = ((vector) sVec); llSay(0, "color is " + ((string) color)); llSetColor(color, ALL_SIDES); state unList; } }
state unList { touch_start(integer n) { vector color = ((vector) llList2String(lVec, 1)); llSay(0, "color is " + ((string) color)); color /= 2; llSay(0, "half color is " + ((string) color)); llSetColor(color, ALL_SIDES); state default; } } A couple of points to note: the strings need to be explicitly cast to vectors and the odd syntax ((vector) sVec) is a defensive habit I've developed because the precedence of explicit casts are odd. The flipping between states was just to make it convenient to show list extraction of vectors. There is more information on typecasts in the wonderful LSL Wiki. Hope that helps.
|
Danny DeGroot
Sub-legendary
Join date: 7 Jul 2004
Posts: 191
|
12-23-2004 16:03
Hi Stinky, Rez a prim and stick this in it:
default { state_entry() { llSay( 0, (string)llGetColor( 0 ) ); llListen( 0, "", llGetOwner(), "" ); }
listen( integer channel, string name, key id, string msg ) { llSetColor( (vector)msg, ALL_SIDES ); llSay( 0, (string)llGetColor( 0 ) ); } }
It'll show you the form it's expecting, which is a string like: "<0,1,0>" only you wouldn't include the quotes in a chat command or a cast. You can get away with properly formed integers or floats between 0.0 and 1.0. Higher numbers are rounded down to 1.0 when setting the corresponding RGB value, even though the higher number is remembered and returned by the object on an llGetColor(). You can also embed arbitrary spaces, like "<0,0, .88>". Anything that's improperly formed will evaluate to the zero vector in llSetColor(). -- danny
|
Stinky Queso
Second Life Resident
Join date: 29 Nov 2004
Posts: 53
|
12-23-2004 17:52
thanks for the quick replies! I got it working perfectly, thanks!
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
12-24-2004 04:00
when translating a string to a vector you need 3 valid floads seperated by comas with a leading "<" and trailing ">". Spaces can be anywhere but before the < or in the float itself. These are all valid vectors. It's actualy better to use (vector)llList2String(rList, rInt) then llList2Vector(rList, rInt) when dealing with a list entry that is a string or key. If it is a vector use llList2Vector(rList, rInt). <.1,1,1.1> <.1, 1, 1.1> < .1, 1, 1.1 > < .1 , 1 , 1.1 > <1.0E+1, 1E2, 1.2E-3> // you get the idea.
_____________________
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
|