Copy link to clipboard
Copied
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
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
...Copy link to clipboard
Copied
Well, I made a new marker, and linked the "length" to that, so that works.
Still curious on the math, though.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Neat trick! Thanks Mathias!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thanks for the clear explanation. Makes total sense. And more proof that now I need to start watching my Javascript udemy course
-Ville
Find more inspiration, events, and resources on the new Adobe Community
Explore Now