FORUMS: list search recent posts

# If statements holding values

FAQ   •   VIEW ALL

 If statements holding values on Jan 6, 2016 at 4:35:41 pm

Hi, 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 !

 Re: If statements holding valueson Jan 6, 2016 at 7:15:23 pm

I 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

 Re: If statements holding valueson Jan 6, 2016 at 7:39:40 pm

First 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)...

 Re: If statements holding valueson Jan 6, 2016 at 7:49:15 pm

This isn't exactly what you're looking for, but you might find it helpful:

http://motionscript.com/design-guide/audio-trigger.html

Dan

 Re: If statements holding valueson Jan 6, 2016 at 8:09:04 pm

I've already seen this webpage and tried these expression but they're not what I4m looking for unfortunately...

 Re: If statements holding valueson Jan 6, 2016 at 8:20:18 pm

Understood. It's just an example of looping back in time to find a past event.

Dan

 Re: If statements holding valueson Jan 7, 2016 at 3:47:53 pm

Are 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.

 Re: If statements holding valueson Jan 7, 2016 at 4:24:47 pmLast Edited By Ymri Scheiner on Jan 7, 2016 at 4:25:28 pm

Not 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...

 Re: If statements holding valueson Jan 7, 2016 at 11:37:14 pm

It 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

 Re: If statements holding valueson Jan 8, 2016 at 12:18:41 am

OK, 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

 Re: If statements holding valueson Jan 8, 2016 at 9:26:10 am

Dan,

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

 Re: If statements holding valueson Jan 8, 2016 at 11:16:46 am

Good point. I guess that would be the case as long as the flip is instantaneous and there's no hysteresis (up and down thresholds are the same).

Dan

 Re: If statements holding valueson Jan 9, 2016 at 5:03:34 pm

Thank you a lot ! I've tried and it works ! Just to know, what does (n%2) means ?

 Re: If statements holding valueson Jan 9, 2016 at 6:45:23 pm

% is the JavaScript modulus operator, which gives you the remainder of a division operation, so (n%2) will be true if n is an odd number, false if it is an even number (assuming n is an integer, as it is in this case).

Dan

 Re: If statements holding valueson Jan 10, 2016 at 3:45:55 pm

Oh ok but shouldn't you put the ==0, or does it recognize you mean if this equals 0 when you put nohting ?

 Re: If statements holding valueson Jan 10, 2016 at 5:21:36 pm

(n%2 != 0) would give you the same result, but anything that's not zero gets interpreted as true.

Dan