Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

vector string madness

Jher Quartermass
Registered User
Join date: 24 Sep 2004
Posts: 18
11-19-2005 16:29
Ok, maybe I'm making a error here, maybe I'm insane.

Is it possible to do something like this?


vector variable1= vector (string variable2);


So I can cheat and do things like

vector red = <1,0,0>;

listen (integer channel,string name, key id, string variable2) {

vector variable1= vector (string variable2);

}



I.E. say "red" on a channel and have it pass the string red as the actual variable name for the vector?

(Like I said, I may be insane. Oh and the above does not work in its present form).
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
11-19-2005 16:58
if you want to turn a color to it's vector you need to know the vector

course you could keep a list and and just do a list find instead.

CODE

listen( integer a, string b, key c, string d)
{
vector color = (vector)d;
if(color == ZERO_VECTOR)
{
if(d == "red")
color = <1,0,0>;
else if(d == "green")
color = <0,1,0>;
}
}
_____________________
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
Jokey Domela
Registered User
Join date: 27 Jul 2005
Posts: 83
11-19-2005 18:46
Maybe you would find something useful in this script...

/15/19/71657/1.html
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
11-20-2005 13:43
From: Jher Quartermass
Is it possible to do something like this?

vector variable1= vector (string variable2);
Assuming I've got the right idea about what you want to do, you've got the right idea, but (1) you're using the wrong syntax, and (2) you're you're using the wrong tools.

Fixing #1 first:
CODE

listen (integer channel,string name, key id, string variable2) {
vector variable1= (vector)variable2;
}


Fixing #2... you don't use a variable, you use a list:
CODE

list name2color = [
"red", <1,0,0>,
"blue", <0,1,0>,
"green", <0,0,1>,
// etcetera...
];

// and then ...

listen (integer channel,string name, key id, string variable2) {
vector variable1;
integer index = llListFindList(name2color, [variable2]);
if(index = -1) variable1 = (vector)variable2;
else variable1 = llList2Vector(name2color, index+1);
}

This way they can say "red" or "<1,0,0>" and you get the same result.
Jher Quartermass
Registered User
Join date: 24 Sep 2004
Posts: 18
11-21-2005 17:09
Thats what I ended up doing. Thanks!