Optional params

For developers using the Construct 2 Javascript SDK

Post » Thu Apr 30, 2015 7:50 am

Hi

I'm making a plugin and want to have functionality equal to "random" in System plugin (mine is seeded). Where you can send in one or two params without using a default value. Is that possible to accomplish for a third party plugin?

The problem is that Construct 2 says "Wrong number of parameters" trying to send in one.
B
3
Posts: 3
Reputation: 181

Post » Thu Apr 30, 2015 8:12 am

@BjornS

There is already a plugin for random that uses a seed. You could possible use that to get ideas, or just make use of cow_trix's plugin.

Here: https://www.scirra.com/forum/plugin-randomplus_t63543
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
84
Posts: 5,391
Reputation: 58,464

Post » Thu Apr 30, 2015 9:13 am

Thank you for the quick reply, I looked up RandomPlus and it seem to have the same "issue" that I. "RandomPlus.RandPlus" requires three parameters mandatory.

It isn't a big issue the min and max value can be mandatory. But I am still curious if it possible to have a third party plugin with optional parameters like the random in System? Or is that only possible since it doesn't have an "edittime.js" (I can't find one)

SysExps.prototype.random = function (ret, a, b)
{
// b not provided: random number from 0 to a
if (b === undefined)
{
ret.set_float(Math.random() * a);
}
else
{
// Return random number between a and b
ret.set_float(Math.random() * (b - a) + a);
}
};
B
3
Posts: 3
Reputation: 181

Post » Thu Apr 30, 2015 9:38 am

You can give the expression the ef_variadic_parameters flag.

https://www.scirra.com/manual/19/action ... xpressions
ef_variadic_parameters
Construct 2 will allow the expression to be used with additional 'any type' parameters past the end of those specified. Any parameters that are specified will still be required and type checked. If no parameters are specified, the expression can be used with any number of parameters at all.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Thu Apr 30, 2015 11:57 am

Thank you! "ef_variadic_parameters" did the trick :)
B
3
Posts: 3
Reputation: 181

Post » Tue Feb 16, 2016 11:56 am

i was trying to follow the beginners tutorial, and i was trying to get the enemies to move left and right. I went to event sheet and select Enemy>Instance variable, then it opened up parameters for "instance variable": Compare instance variable.

Then i set the Instance Variable to Action, Comparison to = Equal to, and Value to right, then i get this message saying "Wrong Number of Parameters 'right does not take 0 parameters (should have 2)

anything wrong with it
B
2
Posts: 6
Reputation: 160

Post » Sun Dec 11, 2016 1:39 pm

That's because the value is a string and you have to write it in quotation marks.

Image
B
2
Posts: 1
Reputation: 152


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest