How to Apply specific values to a Slider Control

Moderators: Disciple, zlovatt

Post Reply
melvin1817
Posts: 1
Joined: March 7th, 2017, 11:26 am

March 7th, 2017, 11:44 am

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.
User avatar
zlovatt
Posts: 21
Joined: October 31st, 2016, 5:00 pm
Location: Los Angeles
Contact:

March 11th, 2017, 1:42 pm

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];
runegan
Posts: 22
Joined: November 4th, 2016, 3:18 pm
Contact:

March 11th, 2017, 5:14 pm

@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 )
User avatar
zlovatt
Posts: 21
Joined: October 31st, 2016, 5:00 pm
Location: Los Angeles
Contact:

March 13th, 2017, 5:46 pm

@runegan Thanks! Forgot about that. Updated my post.
Post Reply