Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Expression, using a slider value as a "length" definition

Community Beginner ,
Mar 11, 2019 Mar 11, 2019

Am I missing something?

I have an expression, where I want to use a linear (ease) transition between 100 to 0, starting from a predefined marker, and having a transition length defined by a slide effect. The idea in the linear function is to define the length of the "tween" as marker+slider value.

Using this expression as source text (for troubleshooting):

endMarker = timeToFrames(thisComp.marker.key("End").time);

tweenLen = thisComp.layer("Target").effect("ValueOut_length")("Slider").value.toFixed(0);

delay = endMarker+tweenLen;

[tweenLen, endMarker, delay]

looks like minus / multiply / divide work in the var delay function, AE yields the correct result, but when I try to add, the result is endMarker value _appended_ with tweenLen value.

If I do

delay = endMarker+5

it works as it should, but then that becomes a "hardcoded" value, which takes away some of the benefit / flexibility.

Am I doing something wrong or is this a bug of sorts? Also, workarounds are welcome!

-Ville

TOPICS
Expressions
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Mar 12, 2019 Mar 12, 2019

toFixed() is the problem here. 

From w3schools: (JavaScript toFixed() Method )

Return Value: A String, representing a number, with the exact number of decimals

So you are actual adding two strings, as assumed.

For your desired outcome, you can go with:

tweenLen = parseInt(thisComp.layer("Target").effect("ValueOut_length")("Slider").value.toFixed(0));

or more common and easier:

tweenLen = Math.floor(thisComp.layer("Target").effect("ValueOut_length")("Slider").value);

BTW: if you try to fade something, t

...
Translate
Community Beginner ,
Mar 11, 2019 Mar 11, 2019

Well, I made a new marker, and linked the "length" to that, so that works.

Still curious on the math, though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 12, 2019 Mar 12, 2019

Not sure what you expect. You are not doing a subtraction anywhere to calculate an actual time differential. All interpolation functions need a start and end parameter, not just one. The rest is just specific to debugging with text layers - mudding up your calculations with .toFixed(), which is solely meant to clip values for display purposes, will of course introduce string processing and adding a string to another string will produce a new string. You need to do the math before actually constructing your strings using math.Round() or whatever, not simply hope AE will handle this automatically.

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 12, 2019 Mar 12, 2019

The linear function was not included   The point was, as I was troubleshooting the math of my values by doing them on a text layer (just to actually see what AE was using as values), I noticed that doing

delay = endMarker+tweenLen produced 305

while

delay = endMarker-tweenLen produced 25

delay = endMarker/tweenLen produced 6

delay = endMarker*tweenLen produced 150

(endMarker value was 30, tweenLen value was 5)

And when I changed it to

delay = endMarker+5 produced 35

So, the question / observation from me is: truncating a slider value with toFixed(0) "seems" to work as expected with other basic math functions, but with an add/+ function it's acting like "string"+"string" concatenation instead of math?

And the lead-up: is that a by-product of not using math.Round to loose the decimals from the slider value?

And if so, what's the way of adding (in a math sense) to get

delay = endMarker+tweenLen to produce 35?

I'm pretty fresh to this scripting game, so this is a good learning process to me

Cheers!

-Ville

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 12, 2019 Mar 12, 2019

By the way, instead of using text layers for debugging, it is much more convenient to throw errors to inspect any value(s) in your code.

See my tweet here

https://twitter.com/mamoworld/status/1101168951185289217

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 12, 2019 Mar 12, 2019

Neat trick! Thanks Mathias!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 12, 2019 Mar 12, 2019

toFixed() is the problem here. 

From w3schools: (JavaScript toFixed() Method )

Return Value: A String, representing a number, with the exact number of decimals

So you are actual adding two strings, as assumed.

For your desired outcome, you can go with:

tweenLen = parseInt(thisComp.layer("Target").effect("ValueOut_length")("Slider").value.toFixed(0));

or more common and easier:

tweenLen = Math.floor(thisComp.layer("Target").effect("ValueOut_length")("Slider").value);

BTW: if you try to fade something, there is a script/effect called Autopacity which is driven by markers (or keyframes or what ever you like).

Cheers,

Martin

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 12, 2019 Mar 12, 2019
LATEST

Thanks for the clear explanation. Makes total sense. And more proof that now I need to start watching my Javascript udemy course

-Ville

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines