VEX: strange behaviour of the "choice" type pragma

   4557   6   1
User Avatar
Member
398 posts
Joined: July 2005
Offline
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).
f = conserve . diffuse . advect . add

fx td @ the mill
User Avatar
Member
7733 posts
Joined: July 2005
Offline
Are you accessing the parameter as a string or as a float? ie. ch() or chs() ?
User Avatar
Member
398 posts
Joined: July 2005
Offline
Well. I use it as int inside my shader and (just for debugging) I've used ch().
Btw. I prefer int type for “menus” because of unpredictable results (well… sometimes unpredictable) in the case of using of strings.
f = conserve . diffuse . advect . add

fx td @ the mill
User Avatar
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.

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)
User Avatar
Member
398 posts
Joined: July 2005
Offline
Arhhh… It's not the problem at all )) I use fit() for this stuff but do you agree that behaviour like that is not cool? RFE? :wink:
f = conserve . diffuse . advect . add

fx td @ the mill
User Avatar
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(“…”))
User Avatar
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!
f = conserve . diffuse . advect . add

fx td @ the mill
  • Quick Links