• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Change value if true, if false keep the value

New Here ,
Jan 27, 2017 Jan 27, 2017

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.

TOPICS
Expressions

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 27, 2017 Jan 27, 2017

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

...

Votes

Translate

Translate
Enthusiast ,
Jan 27, 2017 Jan 27, 2017

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2017 Jan 27, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 27, 2017 Jan 27, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2017 Jan 27, 2017

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

tickerX--X--X--x--x-
value00010010010010010010000000

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2017 Jan 27, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2017 Jan 27, 2017

Copy link to clipboard

Copied

The problem is that I can't check the value of "value" with that expression

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 27, 2017 Jan 27, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2017 Jan 27, 2017

Copy link to clipboard

Copied

LATEST

Thank you very much, that was what I was looking.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines