0 Favourites

AddParam Question

  • So let's say I've defined an expression with two string parameters

    AddStringParam("Opt1","Option1","");
    AddStringParam("Opt2","Option2","");
    AddExpression(5, ef_return_string, "myFunc, "My Plugin", "myFunc", "My Function");
    [/code:fsil8fsp]
    
    and then in a later version of the plugins life, I'd like to add another optional parameter to the expression.
    
    [code:fsil8fsp]
    AddStringParam("Opt1","Option1","");
    AddStringParam("Opt2","Option2","");
    AddStringParam("Opt3","Option3","");
    AddExpression(5, ef_return_string, "myFunc, "My Plugin", "myFunc", "My Function");
    [/code:fsil8fsp]
    
    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.

  • Construct 3

    Buy Construct 3

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

    Buy 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)
    [/code:3l57d569]
    
    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
    
    [url=https://dl.dropboxusercontent.com/u/139218609/examples/Plugins/jszip_beta.zip]Test[/url]
    
    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)