AddParam Question

For developers using the Construct 2 Javascript SDK

Post » Sun Nov 02, 2014 7:34 pm

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

Code: Select all
AddStringParam("Opt1","Option1","");
AddStringParam("Opt2","Option2","");
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.

Code: Select all
AddStringParam("Opt1","Option1","");
AddStringParam("Opt2","Option2","");
AddStringParam("Opt3","Option3","");
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.
B
11
S
2
G
1
Posts: 202
Reputation: 1,580

Post » Mon Nov 03, 2014 2:20 pm

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.
Scirra Founder
B
397
S
236
G
88
Posts: 24,417
Reputation: 194,538

Post » Wed Nov 05, 2014 6:04 pm

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.
B
11
S
2
G
1
Posts: 202
Reputation: 1,580

Post » Wed Nov 05, 2014 9:04 pm

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.
Scirra Founder
B
397
S
236
G
88
Posts: 24,417
Reputation: 194,538

Post » Thu Nov 06, 2014 12:06 am

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.
B
108
S
26
G
271
Posts: 4,471
Reputation: 151,777

Post » Mon Nov 10, 2014 11:29 pm

@Ash

Code: Select all
---------------------------
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

Test

You could open one of the test capx's in the project folder after attempting to add a parameter.
B
11
S
2
G
1
Posts: 202
Reputation: 1,580


Return to Javascript SDK

Who is online

Users browsing this forum: ST314 and 1 guest