Activity › Forums › Adobe After Effects Expressions › If statements holding values
-
If statements holding values
Posted by Ymri Scheiner on January 6, 2016 at 4:35 pmHi, I was wondering how to make my if do statements permanent and not only last during the duration of the if only, and I’ve searched for a few hours and I didn’t found anything and I also couldn’t come with an expression myself.
This is the only thing that blocks me from completing my expression, wich would make a video or picture flip everytime a certain value reaches 1, but “brutally” : with no animation in bewteen.
Thanks !
Dan Ebberts replied 10 years, 8 months ago 3 Members · 15 Replies -
15 Replies
-
Dan Ebberts
January 6, 2016 at 7:15 pmI can’t tell exactly what you’re trying to do, and I apologize if you already know this, but expressions have no memory, so they have to be recalculated at each frame. If your result depends on something that may have happened on a previous frame, you generally need to loop back from the current time, frame-by-frame until you find the event.
Dan
-
Ymri Scheiner
January 6, 2016 at 7:39 pmFirst thanks for the answer, and basically I want my picture to change scale everytime a certain value = 1 but not in between and to make it that it switches between two scales (an output of [-s[0],s[1] or [s[0],s[1] where “s” is the scale property of the layer).
And no I didn’t knew that it was recalculated every frame so now I don’t really know if it’s possible because the event (when that value reaches 1) isn’t regular (it is synchronized with an aduio layer)…
-
Dan Ebberts
January 6, 2016 at 7:49 pmThis isn’t exactly what you’re looking for, but you might find it helpful:
https://motionscript.com/design-guide/audio-trigger.html
Dan
-
Ymri Scheiner
January 6, 2016 at 8:09 pmI’ve already seen this webpage and tried these expression but they’re not what I4m looking for unfortunately…
-
Dan Ebberts
January 6, 2016 at 8:20 pmUnderstood. It’s just an example of looping back in time to find a past event.
Dan
-
Kalleheikki Kannisto
January 7, 2016 at 3:47 pmAre you trying to flip a layer when a value is 1 or more and unflip it when it is less than 1? Then it would be a simple IF/ELSE.
-
Ymri Scheiner
January 7, 2016 at 4:24 pmNot exactly, I want to flip it everytime a value reaches 1 but I want it to keep it’s value until the next flip so : it’s not flipped, then when myy value = 1 it flips until the value reaches 1 again and so on…
-
Dan Ebberts
January 7, 2016 at 11:37 pmIt sounds like it’s a little trickier than I first thought. Your expression needs to figure out how many flips there have been in the past to know which face to present at the current frame. So you probably need to loop from frame 0 to the current frame, counting transitions as you go.
Are you talking about a value that goes from below 1 to above 1? Is that the only transition you care about (i.e., you don’t flip when the value goes from above 1 to below 1)?
Dan
-
Dan Ebberts
January 8, 2016 at 12:18 amOK, here are two scale expression variations for you to play with. The first version will flip the scale every time the value of a slider (with a wiggle(1,3) expression applied for my testing) goes from below 1 to above 1 or, from above 1 to below 1 (both directions):
threshold = 1;
val = effect("Slider Control")("Slider");
fEnd = timeToFrames(time);
fStart = timeToFrames(inPoint);
n = 0;
above = val.valueAtTime(inPoint) >= threshold;
for (f = fStart+1; f <= fEnd; f++){
t = framesToTime(f);
if (above){
if (val.valueAtTime(t) < threshold){
n++;
above = false;
}
}else{
if (val.valueAtTime(t) >= threshold){
n++;
above = true;
}
}
}
if (n%2) [-value[0],value[1]] else value
The second version only flips when the value goes from below 1 to above 1:
threshold = 1;
val = effect("Slider Control")("Slider");
fEnd = timeToFrames(time);
fStart = timeToFrames(inPoint);
n = 0;
above = val.valueAtTime(inPoint) >= threshold;
for (f = fStart+1; f <= fEnd; f++){
t = framesToTime(f);
if (above){
if (val.valueAtTime(t) < threshold){
above = false;
}
}else{
if (val.valueAtTime(t) >= threshold){
n++;
above = true;
}
}
}
if (n%2) [-value[0],value[1]] else value
I hope that helps.
Dan
-
Kalleheikki Kannisto
January 8, 2016 at 9:26 amDan,
The second version definitely looks like it would do it.
(Perhaps I’m not thinking straight, but per my logic “going both directions” would do exactly the same as a simple IF/ELSE flip above or below threshold value.)
Reply to this Discussion! Login or Sign Up