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

If Else issues

New Here ,
Mar 11, 2015 Mar 11, 2015

Copy link to clipboard

Copied

Hello,

Im trying to create an object that moves in the opposite direction and at 95% of the rate of an animated point.

I have set up sliders on my point with controls for both the X and Y axis - and am currently struggling to write the expressions for my object.

So far, I have:

X=thisComp.layer("CONTROLS").effect("Centre ")("Slider");

Y=thisComp.layer("CONTROLS").effect("Centre ")("Slider");

if (X < 2500){

(thisComp.layer("CONTROLS").effect("Centre ")("Slider")*0.95);

}else if{

(thisComp.layer("CONTROLS").effect("Centre ")("Slider")*1.05);

}else{

2500;}

if (Y < 2500){

(thisComp.layer("CONTROLS").effect("Centre ")("Slider")*0.95);

}else if{

(thisComp.layer("CONTROLS").effect("Centre ")("Slider")*1.05);

}else{

2500;}

[X,Y];

TOPICS
Expressions

Views

554

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 , Mar 12, 2015 Mar 12, 2015

Hi!

Dan is right, as usual 🙂

You have to declare variables that you can modify and use.

You set this expression in a position property, right?

I think you should try this way (at least if I understand what you're trying to do) :

//your animated values

X=thisComp.layer("CONTROLS").effect("Centre ")("Slider");

Y=thisComp.layer("CONTROLS").effect("Centre ")("Slider");

//Your variables

X2 = 2500;

Y2 = 2500;

if (X < 2500){

X2 = X*0.95;

} else if (here, another condition, like "X > 2500") {

X2 = X*1.05);

}

if (Y < 2

...

Votes

Translate

Translate
Community Expert ,
Mar 11, 2015 Mar 11, 2015

Copy link to clipboard

Copied

I can't quite figure out what you're trying to do, but I'm pretty sure you're on the wrong track. In your expression, everything between the second line and the last line will have no effect on the result. Maybe more detail about what you're trying to accomplish...

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
Enthusiast ,
Mar 12, 2015 Mar 12, 2015

Copy link to clipboard

Copied

Hi!

Dan is right, as usual 🙂

You have to declare variables that you can modify and use.

You set this expression in a position property, right?

I think you should try this way (at least if I understand what you're trying to do) :

//your animated values

X=thisComp.layer("CONTROLS").effect("Centre ")("Slider");

Y=thisComp.layer("CONTROLS").effect("Centre ")("Slider");

//Your variables

X2 = 2500;

Y2 = 2500;

if (X < 2500){

X2 = X*0.95;

} else if (here, another condition, like "X > 2500") {

X2 = X*1.05);

}

if (Y < 2500){

Y2 = Y*0.95;

} else if (here, another condition, like "Y > 2500") {

Y2 = Y*1.05;

}


[X2,Y2]; //return your 2D value

Cheers,

François

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 ,
Mar 12, 2015 Mar 12, 2015

Copy link to clipboard

Copied

Thank you! This seems to have worked!

Could you possibly explain to me why I needed to use the variables X2 and Y2?

Many thanks

Ollie

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 ,
Mar 12, 2015 Mar 12, 2015

Copy link to clipboard

Copied

LATEST

Well, you want to return a 2D value.

Your expression was returning [X,Y], which is 2D, but just contains your "control" values.

And all the IF ELSE code was actually not affecting the result (except throwing error)

If you want to return the "computed" values (X2 and Y2) you have to:

1_declare X2 and Y2

2_modify (or assign value to) X2 and Y2 according to your IF ELSE condition

3_return X2 and Y2

Having declared X2 and Y2 in the beginning lets you modify them independently.

But you could also have something like this without declaring X2 and Y2:

if (X < 2500 && Y < 2500) {

[X*.95, Y*.95];

} else if (X > 2500 && Y < 2500) {

[X*.1.05, Y*.95];

} else if ... and so on

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