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

Fade in/out with checkbox tool

Community Beginner ,
Aug 21, 2023 Aug 21, 2023

Please help me create objects to fade in and fade out with the checkbox tool. So I want when the checkbox turns on it will auto fade and vice versa. Here's my code for reference:

FI=effect("Fade In")("Checkbox");
FO=effect("Fade Out")("Checkbox");
Duration=effect("Duration")("Slider");
if (FI==1){
if (FI==1&&FO==1){
fadeIn=easeOut(time, inPoint, inPoint+.3, 0, 100);
fadeOut=linear(time, outPoint-Duration*.1, outPoint,0, 100)
fade=fadeIn-fadeOut;
}
fadeIn=easeOut(time, inPoint, inPoint+.3, 0, 100)} else if(FI!=1){value;}
 
if (FO==1){
if (FI==1&&FO==1){
fadeIn=easeOut(time, inPoint, inPoint+.3, 0, 100);
fadeOut=linear(time, outPoint-Duration*.1, outPoint,0, 100)
fade=fadeIn-fadeOut;
}} else if(FO!=1){value;}
 
 
TOPICS
Error or problem , Expressions , How to
679
Translate
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

Community Expert , Aug 22, 2023 Aug 22, 2023

It appears from your code that you only use the Duration slider for fade out, and I'm not sure about the .1 multiplier, but I think I'd structure it like this:

 

FI = effect("Fade In")("Checkbox").value;
FO=effect("Fade Out")("Checkbox").value;
Duration=effect("Duration")("Slider");

if (time < (inPoint + outPoint)/2){
  FI ? ease(time,inPoint,inPoint+.3,0,100) : value;
}else{
  FO ? ease(time,outPoint - Duration*.1,outPoint,100,0) : value;
}

 

 

Translate
LEGEND ,
Aug 22, 2023 Aug 22, 2023

Your rules don't make any sense and thus disable one another. You need to nest them correctly (pseudo code):

 

if (FI == 1)

{

if (FO == 1)

{}

else

{}

}

else

{}

 

Nothing more required. You are making this too complicated.

Translate
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 ,
Aug 22, 2023 Aug 22, 2023

It appears from your code that you only use the Duration slider for fade out, and I'm not sure about the .1 multiplier, but I think I'd structure it like this:

 

FI = effect("Fade In")("Checkbox").value;
FO=effect("Fade Out")("Checkbox").value;
Duration=effect("Duration")("Slider");

if (time < (inPoint + outPoint)/2){
  FI ? ease(time,inPoint,inPoint+.3,0,100) : value;
}else{
  FO ? ease(time,outPoint - Duration*.1,outPoint,100,0) : value;
}

 

 

Translate
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 Beginner ,
Sep 02, 2023 Sep 02, 2023

Thank you I'm still learning so I didn't know that conditional if can be used with time, by the way, why should the 'checkbox' be added with .value? what's the difference?

Translate
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 ,
Sep 02, 2023 Sep 02, 2023

Usually, when you set a variable equal to a control (like a slider or a checkbox) and later reference that variable in the expression, the expression engine assumes you want the control's value, but sometimes it assumes you're referring the object itself, not its value. I don't remember if that was the case here, or if I did it just to be safe. You could try leaving out .value and see if the expression stops working.

Translate
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 Beginner ,
Sep 02, 2023 Sep 02, 2023

just one more question, can you explain about this "FI? ease(time,inPoint,inPoint+.3,0,100) : value;" I thought conditionals should always have a condition (like FI=1 blablabla) so I was quite surprised by "FI?", that's why my code is quite messy.

Translate
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 ,
Sep 02, 2023 Sep 02, 2023

? followed by : is JavaScript's conditional operator. It's just a shorthand way of putting a short if/else on a single line;

 

FI ? ease(time,inPoint,inPoint+.3,0,100) : value;

 

is the same as

 

if (FI) { ease(time,inPoint,inPoint+.3,0,100) }else{ value };

 

Translate
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 Beginner ,
Sep 02, 2023 Sep 02, 2023
LATEST

Thanks a lot sir, now I understand the logic 😉

Translate
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