Page 1 of 1

How to Apply specific values to a Slider Control

Posted: March 7th, 2017, 11:44 am
by melvin1817
I'm trying to have a Slider Control to scrub trough a specific list of values.

This is the list of values:
0.7
1.0
1.2
1.4
1.8
2.0
2.5
2.8
3.5
4.0
4.5
5.6
6.7
8.0
9.5
11
13
16
19
22
27
32
38
45
54
64

I want to connect the slider to a text layer and have the text display whatever the slider value is from the list above.
As you can see in the list above I want to be able to scrub the slider and have it only show those values.
One decimal place in the first few numbers and no decimal place in the rest as the list above shows.
I'm trying to figure out how to code this into the expression of the slider and the blue slider value as well.

Also, can a list of strings be applied to a slider to have the slider scrub trough the list bellow?

 30"
4"
0"7
4
30
500
1000
8000

I want to connect this slider to a text layer and have the text be whatever the slider value is from the list above (including the quotation marks). 

Thank you for your assistance.

Re: How to Apply specific values to a Slider Control

Posted: March 11th, 2017, 1:42 pm
by zlovatt
Hey Melvin,

One approach would be to store all of the values in an array, and then have the slider control which item in the array it returns.

*Edited: forgot clamp() was available in expressions, thanks runegan!*

Code: Select all

// Get the slider
var slider = effect("Slider Control")("Slider");

// Set up the array of values
var valuesArray = [0.7, 1.0, 1.2, 1.4, 1.8, 2.0, 2.5, 2.8, 3.5, 4.0, 4.5, 5.6, 6.7, 8.0, 9.5, 11, 13, 16, 19, 22, 27, 32, 38, 45, 54, 64];

// Clamp the slider, so the possible values are limited to the length of the values array
slider = clamp(slider, 0, valuesArray.length-1);

// get the Nth value from the array, based on the slider value
valuesArray[slider];

The same option would work for the strings, just need to format the array a little differently so that the quotations are preserved--

Code: Select all

var slider = effect("Slider Control")("Slider");
var valuesArray = ['30"', '4"', '0"7', '4', '30', '500', '1000', '8000'];

slider = clamp(slider, 0, valuesArray.length - 1);
valuesArray[slider];

Re: How to Apply specific values to a Slider Control

Posted: March 11th, 2017, 5:14 pm
by runegan
@zlovatt:
In case you don't know: there is a 'clamp' expression function that does the same as your min/max code.

Math.max(0, Math.min(slider, valuesArray.length - 1));

Is the same as:

clamp( slider, 0, valuesArray - 1 )

Re: How to Apply specific values to a Slider Control

Posted: March 13th, 2017, 5:46 pm
by zlovatt
@runegan Thanks! Forgot about that. Updated my post.