eg.
CODE
vector lavender = <0.2,0.2,0.4>;
if(isset("lavender"){
return TRUE;
}
These forums are CLOSED. Please visit the new forums HERE
Isset |
|
|
Tempus Heart
Registered User
Join date: 16 Jan 2006
Posts: 13
|
02-23-2006 12:08
Is there some fuction I can use to check if there's a variable set.
eg. CODE
|
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
02-23-2006 12:45
No, Tempus, LSL variables always have a value - they are never "unset".
What, specifically, are you trying to accomplish? |
|
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
|
02-23-2006 13:04
vector blah=ZERO_VECTOR;
... if(blah!=ZERO_VECTOR) return TRUE; Unless <0,0,0> is a valid vector in your application domain *shrug* _____________________
|
|
Harris Hare
Second Life Resident
Join date: 5 Nov 2004
Posts: 301
|
02-23-2006 13:04
Tempus,
When you define a variable but don't give it a value, it has a "null value" by default. String Null = "" Integer Null = FALSE or 0 Float Null = FALSE or 0 (... I think) Vector Null = ZERO_VECTOR Rotation Null = ZERO_ROTATION Key Null = NULL_KEY Thus, if you've defined a vector called "lavender" and want to see if it's been given a value other than its null value, you could do: CODE if (lavender != ZERO_VECTOR) { |
|
Sky Honey
Coder
Join date: 16 May 2005
Posts: 105
|
02-23-2006 13:18
Is there some fuction I can use to check if there's a variable set. No. If you use a variable that hasn't been declared you get a compile error. If you display a variable that hasn't been assigned a value, you get the default value. For a vector, it's <0.0,0.0,0.0>. There's no way to unset a variable. _____________________
|
|
Tempus Heart
Registered User
Join date: 16 Jan 2006
Posts: 13
|
It's to compare with a string
02-23-2006 13:39
I want to compare predefined vector values set in the script but also being able to set userdefined vector values
so if the user type in my case /33 color lavender the script look for this predefined variable based upon the parsed string command value the user entered "lavender" and set the variable lavender to the current vector value instead of putting 20 if(input_color == "lavedner" {llSetColor } if(input_color = "red" {llSetColor } At Harris hare, think that will work actually the end examplehowever, what I want to do is, take the string which the user entered eg. lavender call the predefined variable and it's vector value and set it as the vector value I want to recolor with. I could just make two arrays, one containing the names and one containing the values and search index of the names and use this index to fetch the value also |
|
Harris Hare
Second Life Resident
Join date: 5 Nov 2004
Posts: 301
|
02-23-2006 14:09
Tempus,
Scripts cannot create a new variables after they've been compiled. What you need to do is use lists. That way you can have some predefined colors and still add new ones to the list while the script is running. list colorNames = ["red","green","blue"]; list colorValues = [<1,0,0>,<0,1,0>,<0,0,1>"]; When someone wants to change to color to red, you use llListFindList to find out the index of the name "red" in the colorNames list and use that same index to find out what vector the color red is in the colorValues list. If you want the user to add new colors, you need to have that be a different command. Instead of "/33 color red" you might make it "/33 newcolor black <0,0,0>" and then add the new name to the end of the colorNames list and the new value to the colorValues list. |
|
Tempus Heart
Registered User
Join date: 16 Jan 2006
Posts: 13
|
02-23-2006 15:24
That's a great idea. My intention was not to create new colors no, just to have a list of variables looking like this:
vector red = <1,0,0> vector blue = <0,0,1> etc.. but instead of using if(color == "blue" {llSetColor() } if color == "red" {llSetColor() } etc.. I could check if the variable was predefined, else I could give an error message... but the newcolor idea, it's a good one. |
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
02-23-2006 15:34
Yes, you'll have to use lists:
CODE
Then your listen handler can be pretty smart. For instance, if someone just says /33 color lavender, you just need to search the names list to see if the color exists, and if it does, go to the vectors list, use the index you found in the names list, and there's your color. If the user types /33 color lavender <0.25, ...>, you can see if the named color exists, if it does, update the associated vector, if not, add a new color name and vector. Obviously, you'll have to take care that the two lists are always synchronized, so you can use the index in one list as the index in the other list. Alternatively, you could set up a '2-dimentional array' with a list too: CODE
Then you search for the name, and the vector is the next position. Now you need to make sure you update the correct vector if someone redefines a color, add a color, vector pair if someone adds a new color, and so on. |
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
02-23-2006 23:25
Alternatively, you could set up a '2-dimentional array' with a list too |