Skip to main content
Participant
May 4, 2024
Question

Having trouble with what would seem to be a simple if then expression

  • May 4, 2024
  • 1 reply
  • 234 views

Hello all,

I'm trying to create a simple expression that will clamp an input based on another value. More specifically, I have a slider for a month input and a day input and I'm trying tp set up the "DAY"  slider so that depending on what month is inputted in the MONTH slider, the DAY slider will only allow values that correspond to actual calendar values. E.g. if the MONTH slider is set to "2" (february) then if you put "32" for the DAY it'll just change it to "28". I wrote this expression but I have no idea what is wrong based on the error which is:

"Property or method named "A" in class 'global' does not exist or is missing. Any help is greatly appreciated!

Here is the code: 

 

value = effect("MONTH")("Slider");

if (value == 1 || value == 3 || value == 5 || value == 7 || value == 8 || value == 10 || value == 12) {
 A = 31;
} else if (value == 2) {
 A = 28;
} else if (value == 4 || value == 6 || value == 9 || value == 11) {
 A = 30;
}
Math.min(Math.max(effect("DAY")("Slider"), 1), A)

This topic has been closed for replies.

1 reply

Dan Ebberts
Community Expert
Community Expert
May 4, 2024

Your expression works for me, but I wouldn't use "value" as a variable name, because it's a reserved word. Also, your code doesn't include what should happen if your MONTH slider is a fraction or outside the 1 to 12 range, so you probably need a final else clause for that possibility (or do some processing to force the MONTH slider value to an integer between 1 and 12).

 

JoshK2Author
Participant
May 4, 2024

Hey Dan,

Thanks so much for this. Actually, changing value to "m" did the trick!