• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Limit slider range + no decimals expression

New Here ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

Hi, im trying to create a custom slider that is going between 0-21, plus I need to keep the numbers with no decimals. 

There are 2 expressions I'm using:

 

clamp(value, 0,21);  /for keeping the range

Math.round(effect("Slider control")("Slider")); /for rounding the numbers

 

The problem is that each one of the expressions cancel each other. Any idea how can they be united to work together?

Thanks!

 

 

TOPICS
Expressions

Views

2.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

If your expression control slider is on a layer named Controller, the easiest solution is to use the value of the slider and the toFixed(number) operator like this:

 

n = thisComp.layer("Controller").effect("Slider Control")("Slider").value.toFixed(0);

 

 You can then clamp the number display and even add some other text like this:

 

n = thisComp.layer("Controller").effect("Slider Control")("Slider").value;
r = clamp(n, 0, 27);
v = Math.floor(r);
"My Number = " + v

 

I prefer something like that. No matter what value you set in the slider, you will only return 0 through 27. Separating the variables like that keeps the expression easier to read, and it reminds me what I'm doing.

 

If you are very comfortable with reading code, you can combine the whole thing in one line like this:

Math.floor(clamp(thisComp.layer("Controller").effect("Slider Control")("Slider").value, 0, 27));

I just find it easier if I declare variables and then operate on the variables one at a time.

 

If you want to limit the values in the slider from 0 to 27, you can apply this expression to the Slider Control directly.

Math.floor(clamp(value, 0, 27))

The only problem with that method is that the Slider Control in the Effects Control Panel will now be disabled. You will only be able to drag the numbers. A cleaner approach would be to edit the slider's range by right-clicking on the slider value in the Expression Controls panel and then editing the Slider Range from zero to 27. Now the slider range is limited. The values will display decimal places, but the Slider will only run from 0 to 27.  Unfortunately, any expression you add to an expression control slider will disable this control unless you are working in the Extended Graphics Panel. That's another discussion.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

LATEST

Thank you very much, Rick

works perfectly!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines