2025-04-28 10:59 AM
Hi, this is related to a previous post I've made: Link
Sorry if this is a double post, but the previous post was technically solved.
I have a script where the A and B dimensions are based on two VALUES{2} lists with length parameters.
I would like the value of VALUES{2} for the B-dimensions to be dependent on VALUES{2} of the A-dimension through an IF statement. Is this possible? I keep getting error messages regarding parameter types with variations of the following parameter script:
VALUES{2} "size" 2.0, "min",
5.0, "max"
VALUES{2} "width" size*2, "minwidth",
size*5, "maxwidth"
LOCK "A", "B"
IF size= "max" THEN
width = "maxwidth"
ELSE
width = "minwidth"
ENDIF
A=size
B=width
PARAMETERS A=A, B=B
2025-04-28 11:31 AM - edited 2025-04-28 11:32 AM
Hello!
I am not very proficient in English, so I will use ChatGPT to help translate the message below. If anything is unclear, please feel free to ask me for clarification.
Regarding your code:
For values{2}, "min" and "max" are only display texts, not actual parameter values. Therefore, setting size = "max", width = "maxwidth", or width = "minwidth" is incorrect in terms of parameter types.
Suggested correction:
VALUES{2} "size" 2.0, "min",
5.0, "max"
VALUES{2} "width" size*2, "minwidth",
size*5, "maxwidth"
LOCK "A", "B"
EPS = 0.00001
IF abs(size-2) < EPS THEN
parameters width = 4
ELSE
parameters width = 25
ENDIF
A=size
B=width
PARAMETERS A=A, B=B
2025-04-28 12:16 PM
As NMK195 said: The "stringified" representation is just there for the user, that's the whole poinf of using it.
However in your particular case it might make sense to actually check for "min" and "max", since the numbers might change.
There is hope: you can use this command parvalue_description ("size")
to retrieve the string representation.
I myself would still not use it since string comparisons are very costly and it is more elegant to just use a local definition like this (I use all uppercase for constants to better distinguish):
!//--in Master script:
EPS = 0.00001
SIZE_MIN = 2.0
SIZE_MAX = 5.5
!//--in Param script:
values{2} "size",
SIZE_MIN, "min",
SIZE_MAX, "max"
!//--in 2D/3D then:
!// be aware of floating point inaccuracy !
if abs(size-SIZE_MIN) < EPS then
!.... do whatever
endif
Happy coding!
2025-05-13 10:46 AM - edited 2025-05-13 10:46 AM
Hi,
I used this in my last script:
if n>0 then
values "A",A_half*2
values "B",range [1,]
else
values "B",range [1,]
parameters A=B
endif
Before this IF the A and B sizes are not defined.
2025-05-14 03:47 AM - edited 2025-05-14 03:48 AM
Hi,
Your 'values' command has an extra comma
the correct format should be as follows:
if n>0 then
values "A" A_half*2
values "B" range [1,]
else
values "B" range [1,]
parameters A=B
endif
2025-05-14 07:53 AM - edited 2025-05-14 07:53 AM
Hi,
VALUES "parameter_name" [,]value_definition1 [, value_definition2, ...]
you can put comma in "values", its optional.
So it is not an error, it is a matter of preference as far as I know 🤷
2025-05-15 04:08 AM
Hi.
You're right, I've never used a comma after 'values' before, so I thought it was incorrect. I tried it again and saw that there's nothing wrong with the code above — the error might be in another line that you didn’t mention earlier. If possible, please upload the file here so everyone can check it more accurately.
2025-05-23 09:28 AM
the values{2} can take arrays as input, and the ui_infields can take arrays as well. (I know the question was anout values(2}, but those 2 topics are connected.
if I have to have dynamic input in either plain entry of the parameter of than in the UI i do something like that:
prepare 3 arrays: 1 for indexes, 2 for strings, 3 for ui pictures in the master script
i put every possible entry for those arrays.
than in the parameter script I double the arrays with different names but with conditional jumps (if.. then...) for the entries that are dynamic
than either I use values with indexes from parameter script or values{2} with indexes and strings (both parameters from parameter script.
Finally in the UI in the ui_infield command I use the arrays defined in master script to avoid possible missing entries on some situations - I had all parametric defined arrays in masterscript without the "full" ones, but in some situations that setup could make errors in the UI.