ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Dan Ebberts Code, What am I doing wrong

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
John Westlen
Dan Ebberts Code, What am I doing wrong
on Feb 9, 2019 at 8:39:57 pm

Hello,
I see that Dan has a lot of knowledge on here, i found a code he wrote for my issue on How to import Json file to after effects and link it to slider. He wrote this code (i edited the /4 part ) :
data = footage("example.json").sourceData;
rampTime = 3;
done = false;
i = t = tPrev = 0;
while (t <= time){
tPrev = t;
t += rampTime + parseFloat(data[i].duration)/ .4;
i++;
if (i >= data.length){
done = true;
break;
}
}
if (done){
parseFloat(data[data.length-1].slider);
}else{
if ((time - tPrev) < parseFloat(data[i-1].duration)/ .4){
parseFloat(data[i-1].slider);
}else{
v1 = parseFloat(data[i-1].slider);
v2 = parseFloat(data[i].slider);
t1 = parseFloat(data[i-1].duration)/ .4;
t2 = t1 + rampTime;
linear(time-tPrev,t1,t2,v1,v2);
}
}

What this does is change the value every four seconds, the only problem is that i would like the slider's value to constantly be changing so for example if i want the value to be 1,000 and the start of the animation and have it show all the numbers leading up to 2,000. 2,000 being my next value at the four second mark. The only problem with this code is that it delays the values for about 1.5 seconds, so what i mean is at the start (0 seconds) it stays at 1,000 and doesn't change until the 1.25 seconds mark and then it displays numbers counting to 2,000 at the four second mark but then delays and stays at 2,000 for 1.25 seconds then changes again.

How can prevent the code from delaying?

My array looks like this:

[
{
"ID": 1,
"slider": 1000,
"duration": .4
},
{
"ID": 2,
"slider": 2000,
"duration": .4
},
{
"ID": 3,
"slider": 3828.52,
"duration": .4
}

]

So to be clear my problem is there is a delay in the animation in the slider, it stays at 1,000 for about 1.25 seconds before it counts up to 2,000 which is at the four second mark.

Thank you!


Return to posts index

Dan Ebberts
Re: Dan Ebberts Code, What am I doing wrong
on Feb 9, 2019 at 10:04:06 pm

I think you need to change the durations in your file from .4 to 4. Also, I had to change the file to a .jsx to get it to load. Then this seemed to work:


data = footage("example.jsx").sourceData;
tNext = 0;
idx = 0;
while (tNext <= time){
idx++;
if (idx >= data.length) break;
tCur = tNext;
tNext += data[idx].duration;
}
if (idx >= data.length){
data[data.length-1].slider;
}else{
vCur = data[idx-1].slider;
vNext = data[idx].slider;
linear(time,tCur,tNext,vCur,vNext);
}



Dan



Return to posts index

John Westlen
Re: Dan Ebberts Code, What am I doing wrong
on Feb 9, 2019 at 10:35:29 pm

Wow thank you so much! I spent a whole day trying to figure this out, I'm still very new to coding but thank you!

I have one more issue, the code you provided works but at each 4 second mark it seems to add to the decimal place in the sliders value so with this array example:
[
{
"ID": 1,
"slider": 100,
"duration": 4.
},
{
"ID": 2,
"slider": 200,
"duration": 4.
},
{
"ID": 3,
"slider": 300,
"duration": 4.
},
{
"ID": 4,
"slider": 400,
"duration": 4.
},
{
"ID": 5,
"slider": 500,
"duration": 4.
},
]
Using this example 0 seconds starts at 100 and when it gets to 4 seconds it shows 200.10 in the slider's value, then when you move to 8 seconds it shows 300.20 in the slider's value and so on. How do i prevent this? You have no idea how helpful this was to me! , but this is the last issue i need help on.


Return to posts index


Dan Ebberts
Re: Dan Ebberts Code, What am I doing wrong
on Feb 9, 2019 at 10:48:41 pm

I'm guessing your comp's frame rate is 29.97 or 23.976, so 4 seconds in the timeline isn't really 4 seconds exactly. You could change your data to accommodate that, but that's kind of messy.


Dan



Return to posts index

John Westlen
Re: Dan Ebberts Code, What am I doing wrong
on Feb 9, 2019 at 11:10:44 pm

it's fine can't complain thank you so much! You're the best!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]