AddParam Question

0 favourites
  • 6 posts
  • So let's say I've defined an expression with two string parameters

    AddExpression(5, ef_return_string, "myFunc, "My Plugin", "myFunc", "My Function");
    and then in a later version of the plugins life, I'd like to add another optional parameter to the expression.
    AddExpression(5, ef_return_string, "myFunc, "My Plugin", "myFunc", "My Function");
    How would I add the parameter without breaking previous projects?
    I get errors (...expects 2 parameters not 3). 
    Could the editor just read the default value and slip it in if it's missing, 
    or is there a optionalstringparam or something similar so my expressions can still take 2 params but could take 3 as well?
    I don't think AddVariadicParams is what I'm looking for.
  • The easiest thing to do is deprecate the expression (add the ef_deprecated flag) and add a new expression with a different name with the new parameter. This preserves backwards compatibility but forces new projects to use the new expression.

    New parameters are automatically filled with a default for conditions and actions, but it's a lot harder to do for expressions since they are parsed from text when loading the project.

  • Thanks at Ash , sorry for the late reply. It seems adding new parameters to actions and conditions causes errors as well? I've deprecated the old aces as a work around.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It shouldn't do, I've done it with official features in the past. You should provide more information otherwise I can only guess at what could possibly have gone wrong.

  • In expression, add "ef_variadic_parameters", see official array plugin -

    AddNumberParam("X", "The X index (0-based) of the array value to get.", "0");

    AddExpression(0, ef_return_any | ef_variadic_parameters, "Get value at", "Array", "At", "Get value from the array. Add second or third parameters to specify Y and Z indices.");

    In action or condition, if the type of parameter added on the last is not a "object type", it could not be filled automatically. i.e, editor could not find a default "object type" in this case.

  • Ash

    Construct 2 Check failure
    Check failure!  This is probably a bug:
    Calling IsActive() on empty Expression class
    Condition: parsed
    File: projects\Expression.cpp
    Line: 189
    Function: bool __thiscall Expression::IsActive(void) const
    Build: release 187 (32-bit) checked
    Component: Construct 2 IDE
    (Last Win32 error: 0)
    Condition 1, and 2 had to be deprecated because of this issue,
    Action 0, 2 , 5, 9 I'd like to add the commented string param
    Expression 4 and 5 had to be deprecated because of this issue
    You could open one of the test capx's in the project folder after attempting to add a parameter.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)