Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions clamping a slider value but having two different effects for ‘above’ and ‘below’ the limits

  • clamping a slider value but having two different effects for ‘above’ and ‘below’ the limits

    Posted by Jim Lefevre on March 14, 2012 at 11:57 am

    I’ve not really used the clamp expression much so I may be starting on the wrong footing here but…

    I have a slider (CLOUD_position_DRIVER) with values 0 to 100

    when CLOUD_position_DRIVER < 0 I want CLOUD_position value = 0
    and
    when CLOUD_position_DRIVER > 100 I want CLOUD_position value = 100

    but obviously in between those two ranges (CLOUD_position_DRIVER between 0 and 100) I want the position to be a variable value.

    So basically I want to clamp it so that below a certain value it reads a fixed first state, between the value a variable state and after a certain value a third fixed state (different to the first fixed state).

    I’ve tried…

    if (effect(“CLOUD_position_DRIVER”)(“Slider”)<0) {0} else {value};
    if (effect(“CLOUD_position_DRIVER”)(“Slider”)>100) {100} else {value};

    but it’s not working, or rather the second statement is working but not the first! Which is why I was thinking that the clamp thing might be something I need? Maybe not?!

    !

    many thanks in advance

    jim

    http://www.jimlefevre.com

    Jim Lefevre replied 14 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    March 14, 2012 at 5:20 pm

    clamp() should work nicely, like this:

    clamp(value,0,100)

    Your expression would have worked if you had use else if(), like this:

    if (value < 0){
    0
    }else if (value > 100){
    100
    }else{
    value
    }

    Dan

  • Jim Lefevre

    March 19, 2012 at 9:26 am

    Ahhh… a stacked if – else -if

    That’s the puppy.

    In actual fact I managed a bit of a work around in the meantime which is far less elegant which pre-works-out a value before it heads into the main if statement

    if (SLIDER_value < 0) then {VALUE_onoff = 0} else {VALUE_onoff = 100);
    VALUE_var = SLIDER_value;

    if (SLIDER_value > 0) then {VALUE_var} else {VALUE_onoff)

    but I’ll go back in and try that other suggestion for the sakes of personal education.

    Thank you thank you thank you

    x
    jim

    http://www.jimlefevre.com

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy