Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Syntax for multi-variable functions?

  • Syntax for multi-variable functions?

    Posted by Lu Nelson on June 28, 2009 at 1:11 pm

    I don’t even know how to phrase an accurate title for this post…

    But I’m wondering if there is a special syntax whereby one can declare a function which can take a *variable* number of variables. There are built-in functions in AE that can do this: such as linear(), which can take either 3 or 5 variables and if you only give it 3 it will assume the missing ones are 0 and 1.

    Is there a way to declare such a function in expressions, or do I have to declare 2 different functions under two different names?

    Thanks,

    LMN

    Lu Nelson
    Berlin, Germany

    [MacProQ2.66, 8GB, Sys10.5.6, FCP 6.0.5, AE 9.0.2]

    Dan Ebberts replied 16 years, 10 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    June 28, 2009 at 1:51 pm

    Inside the function, you can use arguments.length to tell how many arguments were passed to the function. You can use arguments[] to access them if more were passed than are named in the function definition.

    Dan

  • Lu Nelson

    June 28, 2009 at 2:55 pm

    Thanks Dan,

    That was fast — I must have posted at the right time of day;)

    So if I understand correctly, that means if I wanted to define a function that could accept for example 3 or 5 arguments, I could implement a switch() based on whether (arguments.length==3) for example?

    Best,

    LMN

    Lu Nelson
    Berlin, Germany

    [MacProQ2.66, 8GB, Sys10.5.6, FCP 6.0.5, AE 9.0.2]

  • Dan Ebberts

    June 28, 2009 at 4:47 pm

    Sure, that should work.

    Dan

  • Lu Nelson

    June 28, 2009 at 8:04 pm

    Hmm…I’m guessing this also means I have to be careful of what order the arguments are given in, right?

    — like with my e.g. of AE’s built in linear() function: if I give it only 3 arguments it assumes that the ones I am giving are what would have been values 1, 4, and 5 respectively, if it was called with 5 arguments;
    so perhaps in defining the function one should just list the arguments like a1, a2, a3, etc. and then reassign them to internal variables before calculating…does that sound right?

    I’ll try all this out tomorrow, today I’ve just been thinking it through on paper

    Thanks for your replies Dan

    Lu Nelson
    Berlin, Germany

    [MacProQ2.66, 8GB, Sys10.5.6, FCP 6.0.5, AE 9.0.2]

  • Dan Ebberts

    June 28, 2009 at 8:40 pm

    I’ve never tried it, but that sounds right. You could do it like wiggle(), where you have to specify the 3rd and 4th argument to get to the 5th, or you could, as you suggest, assume in your function that if there are only three agruments passed, that they are the 1st 2nd and 5th.

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy