Optional params

0 favourites
  • 7 posts
  • 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.

  • 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

  • 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);

    }

    };

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can give the expression the ef_variadic_parameters flag.

    https://www.scirra.com/manual/19/action ... xpressions

    [quote:2uvw1hc6]

    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.

  • Thank you! "ef_variadic_parameters" did the trick

  • 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

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

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