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

If statement with 3 conditions.

New Here ,
Aug 06, 2022 Aug 06, 2022

Copy link to clipboard

Copied

On Extend Script engine my code works fine. But on JS it’s not just not working, it, it does not give errors, does not put anything into the text layer, but somehow works properly when all the variables are equal 1 (the last if condition). Honestly do not understand why it works somehow, if judging by the Abode post (https://helpx.adobe.com/after-effects/using/legacy-and-extend-script-engine.html) about the difference of engines. JS should not perceive if without else, and I have no one in the code... So th question is how to adapt code to JS.

 

Ts = thisComp.layer("Clock Controler").marker.key("Start").time;
Te = thisComp.layer("Clock Controler").marker.key("End").time;
St = thisComp.layer("Clock Controler").effect("Time start")("Angle");
En = thisComp.layer("Clock Controler").effect("Time end")("Angle");
if (thisComp.layer("Text Controler").effect("Animate Text")("Checkbox") == 1){
S = ease(time, Ts, Te, St, En) * 10
}
else{
S = thisComp.layer("Clock Controler").effect("Time end")("Angle") * 10
}
M = S/60
H = M/60
D = H/24

 

use_secs = thisComp.layer("Text Controler").effect("Use seconds in text ")("Checkbox")
use_hours = thisComp.layer("Text Controler").effect("Use hours in text")("Checkbox")
use_days = thisComp.layer("Text Controler").effect("Use days in text")("Checkbox")


//M
if ((use_hours == 0)&&(use_days == 0)&&(use_secs == 0))
if (Math.floor(M) == 1)"1 Minute"
else
Math.round(M) + "m1 Minutes"
//H
else if ((use_hours == 1)&&(use_days == 0)&&(use_secs == 0)){

hour_str = "h1"
min_str = "m1"

if (Math.floor(H) == 0) hour_str = "1"
if (Math.floor(H) == 1) hour_str = "1 Hour "
if (Math.floor(H) > 1) hour_str = Math.floor(H) + " Hours "

if (Math.floor(M % 60) == 0) min_str = "2"
if (Math.floor(M % 60) == 1) min_str = "1 Minute"
if (Math.floor(M % 60) > 1) min_str = Math.floor(M % 60) + " Minutes"
hour_str + min_str
}
//D
else if ((use_hours == 0)&&(use_days == 1)&&(use_secs == 0)){

day_str = "d1"
min_str = "m2"

if (Math.floor(D) == 0) day_str = "3"
if (Math.floor(D) == 1) day_str = "1 Day "
if (Math.floor(D) > 1) day_str = Math.floor(D) + " Days "

if (Math.floor(M % 1440) == 0) min_str = "4"
if (Math.floor(M % 1440) == 1) min_str = "1 Minute"
if (Math.floor(M % 1440) > 1) min_str = Math.floor(M % 1440) + " Minutes"

day_str + min_str
}
//DH
else if ((use_hours == 1)&&(use_days == 1)&&(use_secs == 0))
{
day_str = "d2"
hour_str = "h2"
min_str = "m3"

if (Math.floor(D) == 0) day_str = "5"
if (Math.floor(D) == 1) day_str = "1 Day "
if (Math.floor(D) > 1) day_str = Math.floor(D) + " Days "

if (Math.floor(H%24) == 0) hour_str = "6"
if (Math.floor(H%24) == 1) hour_str = "1 Hour "
if (Math.floor(H%24) > 1) hour_str = Math.floor(H%24) + " Hours "

if (Math.floor(M % 60) == 0) min_str = "7"
if (Math.floor(M % 60) == 1) min_str = "1 Minute"
if (Math.floor(M % 60) > 1) min_str = Math.floor(M % 60) + " Minutes"

day_str + hour_str + min_str
}
//S
else if ((use_hours == 0)&&(use_days == 0)&&(use_secs == 1)){
sec_str = "s1"
min_str = "m4"

if (Math.floor(M) == 0) min_str = "8"
if (Math.floor(M) == 1) min_str = "1 Minute "
if (Math.floor(M) > 1) min_str = Math.floor(M) + " Minutes "

if (Math.floor(S % 60) == 0) sec_str = "9"
if (Math.floor(S % 60) == 1) sec_str = "1 Second"
if (Math.floor(S % 60) > 1) sec_str = Math.floor(S%60) + " Seconds"

min_str + sec_str
}

//HS
if ((use_hours == 1)&&(use_days == 0)&&(use_secs == 1)){

hour_str = "h3"
min_str = "m5"
sec_str = "s2"

if (Math.floor(H) == 0) hour_str = "10"
if (Math.floor(H) == 1) hour_str = "1 Hour "
if (Math.floor(H) > 1) hour_str = Math.floor(H) + " Hours "

if (Math.floor(M % 60) == 0) min_str = "11"
if (Math.floor(M % 60) == 1) min_str = "1 Minute "
if (Math.floor(M % 60) > 1) min_str = Math.floor(M % 60) + " Minutes "

if (Math.floor(S % 60) == 0) sec_str = "12"
if (Math.floor(S % 60) == 1) sec_str = "1 Second"
if (Math.floor(S % 60) > 1) sec_str = Math.floor(S%60) + " Seconds"

hour_str + min_str + sec_str
}
//DS
else if ((use_hours == 0)&&(use_days == 1)&&(use_secs == 1)){

day_str = "d3"
min_str = "m6"
sec_str = "s3"

if (Math.floor(D) == 0) day_str = "13"
if (Math.floor(D) == 1) day_str = "1 Day "
if (Math.floor(D) > 1) day_str = Math.floor(D) + " Days "

if (Math.floor(M % 1440) == 0) min_str = "14"
if (Math.floor(M % 1440) == 1) min_str = "1 Minute "
if (Math.floor(M % 1440) > 1) min_str = Math.floor(M % 1440) + " Minutes "

if (Math.floor(S % 60) == 0) sec_str = "15"
if (Math.floor(S % 60) == 1) sec_str = "1 Second"
if (Math.floor(S % 60) > 1) sec_str = Math.floor(S%60) + " Seconds"

day_str + min_str + sec_str
}
//DHS
if ((use_hours == 1)&&(use_days == 1)&&(use_secs == 1))
{
day_str = "d4"
hour_str = "h4"
min_str = "m7"
sec_str = "s5"

if (Math.floor(D) == 0) day_str = "16"
if (Math.floor(D) == 1) day_str = "1 Day "
if (Math.floor(D) > 1) day_str = Math.floor(D) + " Days "

if (Math.floor(H%24) == 0) hour_str = "\r"
if (Math.floor(H%24) == 1) hour_str = "1 Hour \r"
if (Math.floor(H%24) > 1) hour_str = Math.floor(H%24) + " Hours \r"

if (Math.floor(M % 60) == 0) min_str = "17"
if (Math.floor(M % 60) == 1) min_str = "1 Minute "
if (Math.floor(M % 60) > 1) min_str = Math.floor(M % 60) + " Minutes "

if (Math.floor(S % 60) == 0) sec_str = "18"
if (Math.floor(S % 60) == 1) sec_str = "1 Second"
if (Math.floor(S % 60) > 1) sec_str = Math.floor(S%60) + " Seconds"

day_str + hour_str + min_str + sec_str
}

Honestly do not understand why it works somehow, if judging by the Abode post (https://helpx.adobe.com/after-effects/using/legacy-and-extend-script-engine.html) about the difference of engines. JS should not perceive if without else, and I have no one in the code...

 

 

TOPICS
Error or problem , Expressions , Scripting

Views

152

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 ,
Aug 07, 2022 Aug 07, 2022

Copy link to clipboard

Copied

The only issue I had in getting it to work (at least it does something--I'm not sure if it's doing what you expect) was that I had to make sure the "Use seconds in text " checkbox control had the space at the end of the name to match your code.

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 ,
Aug 07, 2022 Aug 07, 2022

Copy link to clipboard

Copied

I did notice that if I turn off any of the "Use..." checkboxes the text disappears. I'm guessing that's not the intent.

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 ,
Aug 07, 2022 Aug 07, 2022

Copy link to clipboard

Copied

Also, structure-wise, your //HS section should be an else if, and your //DHS section should be an else. One other thing--leaving out all the semi-colons at the ends of most of your statements doesn't feel right--it seems like it could have unintended consequences...

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
LEGEND ,
Aug 07, 2022 Aug 07, 2022

Copy link to clipboard

Copied

Most of your statements have no else if or else as a fallback, you are not separating the string processing from the actual math and the string processing itself is hugely inefficient and has a ton of redundancies. Your code could likely easily be condensed down to half the number of lines. The biggest issue, however, is that you are not structuring and nesting the statements in a sensible manner, which simply means that the engine will use whatever is the first condition that is met, which may not necessarily be what is correct for any given point in time. Sorry, but it's simply pretty terrible code and you need to work on imbuing it with actual logic and clean it up.

 

Mylenium

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 ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

LATEST

In fact, I figured out the problem on the next day. I apologize for not closing the discussion immediately. The problem was that the JS did not perceive the main "if"(which depend on the checkbox conrollers) structure without "else" (although the inside "if" it handles without problems). In general, the code should convert the value of the angle controller or the difference of two into conditional seconds and, depending on the selected settings, display the text in days, hours, minutes or seconds. As you correctly noticed I am quite bad at programming, so if there are a couple of tips or ideas on how to cut the code - I'm open to suggestions.)

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