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

Use of plus sign "+" is adding text, not performing mathematical addition

Community Beginner ,
Jun 30, 2021 Jun 30, 2021

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!

 

 

 

TOPICS
Error or problem , Expressions , How to , Scripting
155
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

Valorous Hero , Jun 30, 2021 Jun 30, 2021

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

Translate
Community Beginner ,
Jun 30, 2021 Jun 30, 2021

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);

 

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
Valorous Hero ,
Jun 30, 2021 Jun 30, 2021

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

Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
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 ,
Jun 30, 2021 Jun 30, 2021
LATEST

Thank you Roland!  I'll think I'll be using that site frequently in the near future as I learn more.

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