I don't think that's the bug but I wonder why pragma choice behaves in this way.
Try to declare parameter's UI type as
#pragma label type “Type”
#pragma choice type “1” “Linear”
#pragma choice type “3” “Exponential”
and you will see that actual values of this variable will be 0 or 1 (not 1 or 3).
Why? I expect to see 1 and 3 (don't ask me why I need strange values instead of 0 and 1).
VEX: strange behaviour of the "choice" type pragma
4557 6 1- hoknamahn
- Member
- 398 posts
- Joined: July 2005
- Offline
- edward
- Member
- 7733 posts
- Joined: July 2005
- Offline
- hoknamahn
- Member
- 398 posts
- Joined: July 2005
- Offline
- wolfwood
- Member
- 4262 posts
- Joined: July 2005
- Offline
Integer menus have always required numbering from 0 to N. :? It can be annoying but it should be easy to work around.
What about just creating a lookup table? You could either do something like
{
if (ch(“../menu”)==0) {
return 1;
} else if (ch(“../menu”)==1) {
return 3;
} else {
return 0;
}
}
Or you could use a chf() lookup instead.
Ye Ole Help
Warning
For integer fields with a menu, the tokens must be numbered consecutively starting at 0.
What about just creating a lookup table? You could either do something like
{
if (ch(“../menu”)==0) {
return 1;
} else if (ch(“../menu”)==1) {
return 3;
} else {
return 0;
}
}
Or you could use a chf() lookup instead.
if(coffees<2,round(float),float)
- hoknamahn
- Member
- 398 posts
- Joined: July 2005
- Offline
- edward
- Member
- 7733 posts
- Joined: July 2005
- Offline
The behaviour is correct because it works like this:
- ch() obtains the value of the menu parameter as the nth entry in that menu (starting from 0)
- chs() obtains the string token of the menu
It only so happens to look like numbers because you used “1” and “3”. A more obvious example is to set up your menu like this:
#pragma label type “Type”
#pragma choice type “linear” “Linear Interpolation Type”
#pragma choice type “exp” “Exponential Interpolation Type”
So in this example, what is ch() is supposed to return? I hope you see my point.
PS. In this case, instead of a lookup table, the far easier way is to use
int(chs(“…”))
- ch() obtains the value of the menu parameter as the nth entry in that menu (starting from 0)
- chs() obtains the string token of the menu
It only so happens to look like numbers because you used “1” and “3”. A more obvious example is to set up your menu like this:
#pragma label type “Type”
#pragma choice type “linear” “Linear Interpolation Type”
#pragma choice type “exp” “Exponential Interpolation Type”
So in this example, what is ch() is supposed to return? I hope you see my point.
PS. In this case, instead of a lookup table, the far easier way is to use
int(chs(“…”))
- hoknamahn
- Member
- 398 posts
- Joined: July 2005
- Offline
I see your point edward. But idea was… If you have some function which can do different things depending on some input parameter (which should be in range ) and if you want to use the range instead of you have a choice:
1. Use pragma choice “2” “One thing”; “3” “Another one thing” (but now I know it's impossible)
2. Rewrite that function to use string parameters. It's not interesting.
3. Remap parameters and then call the function. Not interesting too.
If we have this syntax
“Some Value” “Some Label”
it's normal to expect that
“2” “Something”
“3” “Something Else”
should work
Concerning to string value and ch() I suppose that ch() should return something like error or undef.
Anyway the things are clear now and I know why I get 0 and 1 instead of expected 2 and 3 Thanks!
1. Use pragma choice “2” “One thing”; “3” “Another one thing” (but now I know it's impossible)
2. Rewrite that function to use string parameters. It's not interesting.
3. Remap parameters and then call the function. Not interesting too.
If we have this syntax
“Some Value” “Some Label”
it's normal to expect that
“2” “Something”
“3” “Something Else”
should work
Concerning to string value and ch() I suppose that ch() should return something like error or undef.
Anyway the things are clear now and I know why I get 0 and 1 instead of expected 2 and 3 Thanks!
f = conserve . diffuse . advect . add
fx td @ the mill
fx td @ the mill
-
- Quick Links