Copy link to clipboard
Copied
Hello, I'm using this code:
if(thisComp.layer("tick 10 frames").transform.opacity==100){
if(thisComp.layer("audio").effect("Both Channels")("Slider")>12){
value=100;
}else{
value=0;
}
}
And I would like that is the first "if" is false don't change the value but after a lot of tries I don't know how to do it.
Now I understand what you mean by 'unchanged'. If you just want it to sample every 10 frames, the easiest thing would be to put
posterizeTime(3);
at the start of the expression setting the frame rate you want the resulting expression to sample at (i.e. 30 fps divided by 10) and remove the outer 'if' statement altogether.
Otherwise you'll need a more convoluted expression, using nearestKey() to find the nearest keyframe from the tick property, check if the time of it matches the current time, if not
...Copy link to clipboard
Copied
You use "value" to read the current value of the property with the expression at the current time (i.e. just value as an expression acts like there is no expression) so it would be something like;
if (thisComp.layer("tick 10 frames").transform.opacity==100) {
if (thisComp.layer("audio").effect("Both Channels")("Slider")>12){
100;
} else {
0;
}
} else value;
Copy link to clipboard
Copied
It doesn't work, when the first if is true and the second false the result is 0 but the next frame it's 100. I tried changing my 100 to another number and it doesn't matter, result is always 100 except when first if is true, in that case it can be 0 or 50 and it works as intended.
Copy link to clipboard
Copied
Is the value of the property 100 when the expression is turned off? "value" essentially gives you the value of the property when the expression is disabled.
Perhaps where it says "100" in the expression you actually want that to be "value" too? I can't really say with the information you've gave. You asked that "if the first 'if' is false the value shouldn't change", which is what the expression I wrote should do, assuming you meant "if the first 'if' is false the value should be the pre-expression value".
if (tick 10 frame layer's opacity is 100) if (Both Channels is greater than 12) make value 100, otherwise make it 0
otherwise use the pre-expression value
Copy link to clipboard
Copied
What I want to do is a little animation that reacts to the audio, when it's greater than 12 it's one image, if not, the "base" one, I know how to do this but I don't want to do it every frame so I use "tick 10 frames" but I want that the image only changes when the ticker activates, in the meantime it should have the value given when the the expression is analyzed. For example:
X=Indicates activation of ticker
ticker | X | - | - | X | - | - | X | - | - | x | - | - | x | - |
value | 0 | 0 | 0 | 100 | 100 | 100 | 100 | 100 | 100 | 0 | 0 | 0 | 0 | 0 |
Copy link to clipboard
Copied
Expressions have no memory. If you want it to figure out if something has happened in the past, you need to loop back in time, frame by frame, using valueAtTime().
Dan
Copy link to clipboard
Copied
The problem is that I can't check the value of "value" with that expression
Copy link to clipboard
Copied
Now I understand what you mean by 'unchanged'. If you just want it to sample every 10 frames, the easiest thing would be to put
posterizeTime(3);
at the start of the expression setting the frame rate you want the resulting expression to sample at (i.e. 30 fps divided by 10) and remove the outer 'if' statement altogether.
Otherwise you'll need a more convoluted expression, using nearestKey() to find the nearest keyframe from the tick property, check if the time of it matches the current time, if not take the time of the previous key and find the value of the audio channel at that time to determine what the result should be. As Dan says, expressions are resampled every frame and have no memory of what's gone before.
Copy link to clipboard
Copied
Thank you very much, that was what I was looking.