slider evaluates to 0 when used with charAt() method
by Caleb Payne on Jun 19, 2019 at 5:46:57 pm
Hello! this post is more about my understanding of the language than it is a problem to solve.
I'm using the charAt() method on a text layer's sourceText property, and attempting to pass sliderValue
as its first and only argument, where sliderValue
points to a slider effect on the same layer, like this:
//expression applied to a text layer's sourceText property
sliderValue = effect('Slider Control')('Slider');
myString = 'quickbrownfox';
newText = myString.charAt(sliderValue);
I would expect this to return a single letter from the "quickbrownfox" string, corresponding to the index provided by the slider, as long as it's within range. For example, if my slider is set to 4, the text should be "k."
However, the above always returns "q" suggesting that sliderValue
is evaluating to 0 when passed into charAt().
One strange thing is that is that adding or subtracting 0 or (even an empty string) to sliderValue
makes it work as expected. Alternatively, using one dimension of a point control in place of a slider works too. While writing this I've also found that wrapping sliderValue
in a parseInt() or Math.floor() method is another work-around.
It appears as if charAt() can't make sense of a slider value unless it's deliberately typed as an integer.
Does that sound right? I've never run into this before so I'm just wondering if anyone has had similar experiences or has further insight.
Re: slider evaluates to 0 when used with charAt() method
by Kalleheikki Kannisto on Jun 19, 2019 at 6:15:24 pm
You want to use Math.round(effect('Slider Control')('Slider').value)
there. Note also .value
at the end to retrieve the value of the slider rather than the slider as an object.
Senior Graphic Designer