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

Why do I get non-integer numbers when using script?

Participant ,
Jan 22, 2022 Jan 22, 2022

Hi guys, I am trying to build a simple script that sets keyframes automatically every 'i' seconds and changes  position by fixed amount of pixels ( in my case -640) on every keyframe. 

I wrote a simple lines of code to do it: 

var curX = 320.0;
    for (i = 10; i <= 240; i += 5){

    selection[0].setValueAtTime(i, [curX,540])
    curX += -640.0;
};

 

 

 

 

But all values of every keyframe are non-integer numbers, although in the code above there are only integers. Here is the some values I get when running the code:

10 sec position x:320 y: 540;

15 sec position x:-321,9194 y: 540;

19,29 sec position x:-958,29 y: 540;

24.29 sec position x:-1598,9316 y: 540;

......

....

0;02;59;27  position x: -21433,1681 y: 540;

selection in this code is app.project.activeItem.selectedProperties, so selection[0] is position

Any suggestion why is this happening and how to fix?

Thank you in advance 🙂

TOPICS
Resources , Scripting
433
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 ,
Jan 22, 2022 Jan 22, 2022

Integers can be perfectly used to represent fractional numbers. That's a general misunderstanding many people have. If you want whole numbers, simply add a Math.round().

 

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
Participant ,
Jan 22, 2022 Jan 22, 2022
I did
var
curX = Math.round(320.0);
for (i = 10; i <= 240; i += 5){
selection[0].setValueAtTime(i, [Math.round(curX),540])
curX += Math.round(-640.0);
};
but it gives the same result
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 ,
Jan 23, 2022 Jan 23, 2022

Well, then straighten out your math further by using timeToFrames() and such or additional rounding.

 

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 Expert ,
Jan 23, 2022 Jan 23, 2022
LATEST

How do you check the value of the keyframe? Do you read the value shown in the time-line? Do you see the same value in the dialog that pops up when you double-click on a keyframe?

If you see clean int numbers in the dialog, but point numbers in the timeline, then most likely your keyframes are not exactly at the start of a frame, but in-between frames.

If your comp has a frame rate of 23.976 fps, for example, and you insert a keyframe at 1s, then this keyrame sits a tiny bit before the (beginning of the) 25th frame, (since after 1s only 23.976 and not full 24frames have been played, yet).

 

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