Skip to main content
easygoing_idea1549
Inspiring
June 4, 2017
Answered

Expression: I am stuck

  • June 4, 2017
  • 1 reply
  • 812 views

Hi, could someone please tell me whats going on here:

var i=1;

var Banana;

if (comp("Comp 1").layer("Calender_Pre").effect("STAY!")("Checkbox") == 0)

//i = 0

Banana = 20

else if (i == 0)

//i++

Banana = 25

else if (i >= 0)

Banana = 13;

(Banana);

This code seems to work fine until i uncomment either "i=0" on line 4, or "i++" on line 8. If i uncomment "i=0" i get "Error at line 7...illegal use of reserved keyword 'else'", when i uncomment "i++" i get the same Error at line 11.

Why am i allowed to assign a value to "Banana" inside the if statements, but not to "i"?

Thanks and kind regards,

This topic has been closed for replies.
Correct answer Horshack

You have to use curly braces after an if() statement if you want more than one line to execute as part of the if(), otherwise the conditional chain stops after the line following the if(), which means there is no longer an if() to match the else to. Also, get in the habit of ending all your assignment statements with a semicolon - it will prevent issues for you later on.

Corrected code:

var i=1;

var Banana;

if (comp("Comp 1").layer("Calender_Pre").effect("STAY!")("Checkbox") == 0) {

     i = 0;

     Banana = 20;

} else if (i == 0) {

     i++;

     Banana = 25;

} else if (i >= 0)

     Banana = 13;

(Banana);

1 reply

Horshack
HorshackCorrect answer
Legend
June 4, 2017

You have to use curly braces after an if() statement if you want more than one line to execute as part of the if(), otherwise the conditional chain stops after the line following the if(), which means there is no longer an if() to match the else to. Also, get in the habit of ending all your assignment statements with a semicolon - it will prevent issues for you later on.

Corrected code:

var i=1;

var Banana;

if (comp("Comp 1").layer("Calender_Pre").effect("STAY!")("Checkbox") == 0) {

     i = 0;

     Banana = 20;

} else if (i == 0) {

     i++;

     Banana = 25;

} else if (i >= 0)

     Banana = 13;

(Banana);

easygoing_idea1549
Inspiring
June 4, 2017

Horshack Hi, thanks for the answer, that does make sense, sadly it does not fix the Problem i have with this Project...I think i am approaching it wrong. would you be so kind and take a look at my other thread? Expression: Snapshot of current value

Thanks