Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Divide by zero? error on first frame

  • Divide by zero? error on first frame

    Posted by David Cabestany on May 5, 2016 at 10:00 pm

    I’m using the expression below to have a counter go up in relationship to a slider that is applied elsewhere, this counter shows the percentage of occupancy in a parking lot and has to be accurate.

    The expression works great from the second frame onwards, but in the first frame it gets disabled with the all too familiar invalid numeric value, divide by zero? error.

    I’m guessing some type of conditional should help me here, but I’m not exactly clear on exactly what it needs to include.

    Any help?

    Thanks,
    D.

    totalSp=Math.round(thisComp.layer("183").text.sourceText)+Math.round(thisComp.layer("752").text.sourceText);
    a=thisComp.layer("183").effect("Slider Control")("Slider");
    t2 =thisComp.layer("183").effect("Slider Control")("Slider").key(2);
    percentAvail=(a*100)/totalSp;
    r=linear(a,0,t2,0,percentAvail);
    Math.round(r)+"%";

    David Cabestany replied 10 years, 4 months ago 2 Members · 12 Replies
  • 12 Replies
  • David Cabestany

    May 5, 2016 at 10:52 pm

    Ok, so I revised my expression to this.

    The problem now is that the amount is stuck, meaning it won’t update as the sliders move.
    I checked each part of the expression using a text layer and everything works, but when I put it together like this it stays fixed on 20(%) which is the final value the slider is supposed to reach.

    D.

    a=thisComp.layer("183").effect("Slider Control")("Slider");
    t=thisComp.layer("935").effect("value")("Slider");
    p=(a*100)/t;
    m=Math.round(p);
    m+"%";

  • Dan Ebberts

    May 5, 2016 at 11:30 pm

    It works for me when I scrub either of the sliders.

    Dan

  • David Cabestany

    May 6, 2016 at 1:06 am

    I revised the expression further.

    It’s the weirdest thing. In one layer it kind of works (although returning inaccurate values), in the other it’s stuck in one number, the final value.
    I sent it to Tim over at Adobe at his request, but here’s a link in case you want to check it.

    https://dl.dropboxusercontent.com/u/35786640/percentBug.aep

    The soloed layers are the ones with this expression.

    Best,
    D.

    a=thisComp.layer("183").effect("Slider Control")("Slider");
    t=a+thisComp.layer("752").effect("Slider Control")("Slider");
    p=(a*100)/t;
    Math.round(p)+"%";

  • Dan Ebberts

    May 6, 2016 at 2:47 am

    If you look at what’s going on with the sliders, you’ll see that a works out to always 19.5% of t, so it looks to me likes it’s doing what you’re telling it to.

    Dan

  • David Cabestany

    May 6, 2016 at 3:14 am

    But the slider is animating over time, how come the value does not reflect this?
    The other layer is doing it and has the same instruction, only looking at different sliders, which in turn are also deriving their animation from the same original set of keyframes.

  • David Cabestany

    May 6, 2016 at 3:19 am

    I tested the variables separately, a and t. They both animate when they are one their own.
    It’s the 3rd variable, p which is staying on 19.57, but I don’t get why, both a and t are changing their values over time, based on the slider.

  • Dan Ebberts

    May 6, 2016 at 3:20 am

    Move the time indicator to somewhere, harvest the two slider values, and manually do the same calculation of p that your expression does.

    I’m guessing 19.5%.

    🙂

    Dan

  • Dan Ebberts

    May 6, 2016 at 3:23 am

    Yes, but they change together in a way that keeps the result at 19.5%.

    Dan

  • David Cabestany

    May 6, 2016 at 3:27 am

    Crap. You’re right. As usual.

    So, why the expression in the second layer animates over time? Is it because the sliders are also referencing the first set of keyframes using a linear expression?
    I honestly don’t know what’s going on here.

    Is there a way to make the first layer behave the same way as the second one?

    Best,
    D.

  • Dan Ebberts

    May 6, 2016 at 3:37 am

    >Is it because the sliders are also referencing the first set of keyframes using a linear expression?

    Yes, I believe so.

    >Is there a way to make the first layer behave the same way as the second one?

    Well, you could keyframe it.

    What is it that you’re trying to do? I’m thinking that maybe you’ve over-complicated it.

    Dan

Page 1 of 2

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy