Copy link to clipboard
Copied
I'm working on a little project to display recorded data from quadcopter flights on video and am very new to writing expression code. I have the fundamentals working as desired, but I am having issues while trying to add "fine tuning" capabilities such as biasing the recorded data. To try and achieve biasing, I created a slider effect "HeadingAdjustment" to set the desired bias value and used the following expression to try and add that bias value to the data pulled from the "DataSource" csv file:
var Heading = (footage(DataSource).dataValue([21, DTime]).toFixed(0) + thisComp.layer("Globals").effect("HeadingAdjustment")("Slider"));
Lets say the recorded data is "95" and the HeadingAdjustment slider is set to 10. I want the data displayed to show "105", but it shows "9510" ("10" appended to "95") instead.
How do I get the variable definition to perform mathmatical addition rather than adding text / strings?
Thank you!
Reading data from a dataset is essentially reading a text file. Hence the values you see are in effect just an object to AE.
You'll have to convert the Heading to a number and you use the parseFloat() method to do this.
So, writing like this should work -
var Heading = (footage(DataSource).dataValue([21, DTime]).toFixed(0) ;
parseFloat(Heading) + thisComp.layer("Globals").effect("HeadingAdjustment")("Slider"));
More info on parseFloat() can be found here - https://www.w3schools.com/jsref/jsref_parsefloat.asp
Copy link to clipboard
Copied
Wouldn't you know it after some additional searching I find a similar topic "parsing number text string to numeric value" and learn of add() expresstion. Code that achieves the goal (may not be most efficient, but works):
HeadingData = footage(DataSource).dataValue([21, DTime]).toFixed(0);
HeadingBias = thisComp.layer("Globals").effect("HeadingAdjustment")("Slider");
Heading = add(HeadingData, HeadingBias);
Copy link to clipboard
Copied
Reading data from a dataset is essentially reading a text file. Hence the values you see are in effect just an object to AE.
You'll have to convert the Heading to a number and you use the parseFloat() method to do this.
So, writing like this should work -
var Heading = (footage(DataSource).dataValue([21, DTime]).toFixed(0) ;
parseFloat(Heading) + thisComp.layer("Globals").effect("HeadingAdjustment")("Slider"));
More info on parseFloat() can be found here - https://www.w3schools.com/jsref/jsref_parsefloat.asp
Copy link to clipboard
Copied
Thank you Roland! I'll think I'll be using that site frequently in the near future as I learn more.