ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Holding a value

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Garrett Dove
Holding a value
on May 7, 2019 at 5:23:28 am

Okay. So, both me and my partner are complete and utterly new to the expression world, because for the most part, we use very few expressions in the first place.

What we're essentially trying to do, is create a videogame health-bar, and it goes down every time an audio que plays.

We know how to make it go DOWN when the audio plays, but then it goes back up to the original value instead of staying down, and then adding more, and more as each audio que plays.

This is our current code, and yes, it's probably horrible. Like I said, we barely know what we're doing. The problem we're having is it isn't holding the current value when it adds the 10 to the linear wipe we're using to tick the health bar down. I feel like this should be simple, but we're not sure. ANY help would be greatly appreciated.

Notes about it:
- "audio" is the keyframes from the audio layer, made easier by Sound Keys
- counter being set to 51, is because the linear wipe doesn't make a visual difference until it goes up to 52, and then it ends at 94 (yes I'm aware
of how dumb that seems).
-audio > 35 is the threshold for when we want the health to tick down, and by 10(%) we want it to go down every time it hits. We were thinking
that with an else of "counter + 0" we thought it would just keep the value, and then anything else is that isn't over that threshold of 35 wouldn't
add anything.
This of course wasn't the case.

audio = thisComp.layer("Null 1").effect("Sound Keys")("Output 1");

counter = 51;

if (audio > 35) counter + 10; else counter + 0;

Return to posts index

Dan Ebberts
Re: Holding a value
on May 7, 2019 at 7:36:28 am

One of the trickiest things to get used to with expressions, is that no data generated by your expression persists from one frame to the next, so there is no "holding" a value--you have to recreate it on every frame where you need it. There are some tools to help you do that, valueAtTime() being one of the most useful. So for your example, your expression might have to loop through the timeline, frame by frame, up to the current frame, using valueAtTime() to find out how frames in the past the audio value was above 35 (or how long ago it went above 35, depending on what you're trying to do) and base your calculation on that.


Return to posts index

Kalleheikki Kannisto
Re: Holding a value
on May 7, 2019 at 12:11:49 pm

SoundKeys can do an accumulative build-up of values, so you should use that option to get the output keyframes.

Kalleheikki Kannisto
Senior Graphic Designer

Return to posts index

Garrett Dove
Re: Holding a value
on May 7, 2019 at 3:59:29 pm

Thank you both for your replies, we'll give it another go with those things mind!

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 All Rights Reserved