[Closed] Case expression
Hi all. as far as i know, the “case” expression works like this:
(from the maxscript reference) “Only the first expression whose label matches the test expression is evaluated”
Is there a way that works like case, but with multiple evaluations?
like
a=1
case of(
(a<2): print "ok_1"
(a<1.5):print "ok_2"
)
Right now, it would only print “ok_1”. I’d like something like “Case of” but that doesn’t stops after the first valid test. Anything like that in maxscript? Or “if… else” is the only way?
You’d have to nest your cases, or use an if statement. Case does not change. The only way your particular value case would work (ie. checking if lower and lower numbers are greater than a), would be to put the numbers in acending order, like so:
a=1
case of
(
(a<1.5): print "ok_1"
(a<2):print "ok_2"
)
That way, if the number was less than 2, but not less than 1.5, the second case would be evaluated.
If you need cascading checks in a case statement, you’re probably going to have to use a loop.