After Effects: Javascript - Undefined value used in the expression(Could be out of range array subscript)

Viewed 5178

I'm not a programmer by any means. I'm an animator trying to use JS expressions in After Effects. I'm getting an "Undefined value used in expression" error on line 1 where I define a variable.I already showed it to my friend on discord who is a cs major, and he had no clue what was wrong with it.

enter image description here Here's just a paste of the code if you need it:

var count = 1;

if (framesToTime(time) % 12 == 0) {
count = count + 1

    if (count % 2 == 0){
        thisProperty = 95
    } else {
    thisProperty = 20
    };
} ;
4 Answers

Ok I don't know why the hell this fixed it, but I changed the name of the variable from "count" to just "x" and it works now. Go figure

Try it.

var count = 1;

if (framesToTime(time) % 12 == 0) {
    count = count + 1;

    if (count % 2 == 0){
        thisProperty = 95;
    } else {
       thisProperty = 20;
    }
}
thisProperty;

In your code, thisProperty has become an ordinary variable. If you write its name at the end of the code, then its value will be assigned to the property.

In AE, if there is nothing inside an if statement or the if statement contains malformed/error code you will receive this error. Put a temp value inside the curly braces or something to process and ensure nothing inside will throw an error.

I also received this error with this:

pastTime = timeToFrames(time)-1;
curPos = transform.xPosition;
pastPos = transform.xPosition.valueAtTime(framesToTime(pastTime));

if (curPos-pastPos[0] != 0) {

// Here is the problem in my case. added a value here 99 to fix until finished testing.

}
else {
        effect("Angle Control")("Angle")
}

if/else statements are strict

I got this error because there was a missing semicolon.

Related