Skip to main content
Known Participant
December 17, 2018
Question

Layer Hits Error When Using Variable in Expression Linked to Slider

  • December 17, 2018
  • 1 reply
  • 646 views

I'm using Dan Ebberts' inertial bounce code. If I leave the variables as simple assignments, like below, it works:

amp = .25;

freq = 2.0;

decay = 6.0;

n = 0;

if (numKeys > 0){

n = nearestKey(time).index;

if (key(n).time > time){

n--;

}}

if (n == 0){ t = 0;

}else{

t = time - key(n).time;

}

if (n > 0){

v = velocityAtTime(key(n).time - thisComp.frameDuration/10);

value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);

}else{value}

However, if I create and link Sliders to modify those variables (so as to do so globally within the file) it catches an error:

amp = thisComp.layer("Bounce Controls").effect("Amp")("Slider");

freq = thisComp.layer("Bounce Controls").effect("Freq")("Slider");

decay = thisComp.layer("Bounce Controls").effect("Decay")("Slider");

n = 0;

if (numKeys > 0){

n = nearestKey(time).index;

if (key(n).time > time){

n--;

}}

if (n == 0){ t = 0;

}else{

t = time - key(n).time;

}

if (n > 0){

v = velocityAtTime(key(n).time - thisComp.frameDuration/10);

value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);

}else{value}

The error is:

"Error at line 19 in property 'Scale' of layer 18 ("Title_of_Layer") in comp 'Title_of_Comp'. Invalid numeric result (divide by zero?)., an expression was disabled as a result of an error."

Any insights on why? The variables are (in theory) identical. I'm sure I'm just missing something in the fundamentals. Thanks for any help!

This topic has been closed for replies.

1 reply

Known Participant
December 17, 2018

I was wrong-- the error has nothing to do with the added Slider controls.

I found an answer from Dan Ebberts himself:

<quote>

My guess is that the value of t must be getting large enough to cause the Math.exp() function to overflow. [...] Try changing the first line of the last section from this:

if (n > 0){

to this:

if (n > 0 && t < 1){

<end quote>

Known Participant
December 18, 2018

@ADMIN: Can I edit the title of this thread to better reflect the issue and outcome?

Ision Industries
Inspiring
January 4, 2019

Hi Devans_Scout,

I am glad I came across this post. Although I changed the first line of the last section to if(n > 0 && t < 1){ and the inertial bounce expression is still not linking to the slider controls. What is happening?