Is there a way to create Expression overloads??

  • Is there a way to create Expression overloads??

    for example

    let's say i have 2 expressions Sum(a,b) and Sum(a,b,c)

    is there a way to have both of these expression share the same expressionName but have construct determine which one to use based on the number of param passed in? this is a very trivial example which we can use varadic param for? but i'm think of a more complex example which a varadic param cannot be used, i'm just wonder if there is a way to have the same expression name instead of having to add a separate name for each function?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • When u use a variadic parameter, it's still calling one expression. It just returning an array as a Param.

    So I would need to handle all the cases in that expression to account for all the Parameters I'm expecting.

    I guess if the max Param I'm expecting is 3 I can just ignore every other Param after that.

    As for documentation? Can u document the parameters? In a variadic function?

  • You can compare the number and types of arguments and vary the expression depending on that. It's only a simple flag to say "unlimited extra arguments are allowed at the end". There aren't any options to finer control it, because nothing else in all of Construct needs it. Generally a variadic parameter is useful for math functions e.g. allowing the max expression to take any number of arguments and return the maximum of all of them. If your expression isn't doing something like that - maybe you should just have two expressions?

  • Thanks I think that's a cleaner way

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)