[R109] Functions: No named parameters?

0 favourites
  • 8 posts
  • One of the best parts of the Functions plugin by rexrainbow was I could name a parameter with a string, like "BulletX" and "BulletY". With the new built in function object/event though it seems we can only access them by numbers.

    Is there no way around this? Will this maybe be updated in a future release? It's nice having this built in, but calling and setting parameters by number quickly gets out of control.

  • The official Function plugin from Classic also only used numbers for parameters, and the C2 Function plugin is based on the same. That's the main reason why. Also it's difficult to make the UI for variadic parameters within the editor (the 'add parameter' and 'remove parameter' links) when you need to specify both a name and a value. I think we'll leave it as it is for now - you could try dumping all parameters in to local variables in a function event so then you can reference them by name. That also allows for nicer syntax (ParamA + ParamB rather than Function.Param("ParamA") + Function.Param("ParamB")) as well as error checking (ParamC is rejected, but Function.Param("ParamC") is allowed).

  • Having the parameters inside the function helps a little (although it adds an extra step to maintenance and adds to the growing list of variables in the expression helper), but it leaves the problem that A) It's unclear what the parameters are from the action calling the function since it only separates by comma, not name, B) the action calling the function has its variables mangled together. Compare the format of the plugin from rex to the native function call (using some completely made up code for example purposes):

    Comparison screenshot between the rex plugin and native plugin

    Now I could make these variables in the event calling the function too, but now I have 3 variables calling the action and 3 variables naming the parameters inside the function.

    You also have to hope that you never decide to replace the order of your variables - Suddenly "Function.Param(0) + Function.Param(1) / Function.Param(2)" becomes completely different when you decide you don't need parameter 1 any more - Function.Param(2) becomes Function.Param(1)and you need to refactor because the position of the parameters changed.

    I hate to complain about the awesome work you guys are doing, but it seems like right now the plugin from rex is actually more powerful and easier to use. It just seems that using numbers to define parameters as well as requiring local variables on both sides to make the code readable is probably the only thing I can think of in C2 that makes things harder than regular programming <img src="smileys/smiley1.gif" border="0" align="middle">

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I just don't like the idea of using strings as parameter names. If we went down that route, I'd want Construct 2 to be able to tell you in the editor if you used an incorrect parameter name, to help prevent you making mistakes from typos. That would mean using some kind of built-in expressions (like local variables) which aren't just simple strings. I'm not sure how we could design that.

  • It would be nice to at least have the option - I would be much less concerned about a mistyping a string while having a clean project than mistyping a number and having a messy project (ie. I can typo a parameter index from Function.Param(1) to Function.Param(11) and C2 will not warn me). I'm not suggesting you switch from one to the other, it would just be nice if it supported both like the plugin by rex. Having a prompt when using a string (like when using a layer by name) would be handy, but I don't think it's critical considering there's no prompt for parameter typos by number anyway.

    Also there are already parts of C2 that take a string as a parameter with no error checking - For example, calling a key in a dictionary.

    This is just all my opinion. I have no idea how the rest of the C2 community feels about this, so maybe they are not as fussed as I am. I'm more than happy to keep using the plugin by rex, but it would be nice to see some of those features cross over into a plugin that is supported 'in-house' as it were.

  • I second this. For now I will keep using rexrainbow's object for the convenience of being able to name parameters. In my opinion it was a big improvement over Classic's function object mainly for that reason.

  • I agree that the official function plugin should keep using "number" index, since it makes the interface simple. "expression:Call" could not use "string" parameter as well.

    To support "string" index, a solution is using my hash table plugin or official dictionary to transfer parameters into JSON string and set this string in parameter of official function. In "On function", unpack the JSON string by hash table plugin or official dictionary. to get parameter by string key.

    (string key, value) -> hash table -> JSON string -> function parameter 
    -> "call function -> "on function" 
    -> function parameter (JSON string) -> hash table -> (string key, value)

    <img src="http://i1081.photobucket.com/albums/j352/rexrainbow1/FnHashtable.png" border="0">

    Edit:

    I update my hash table plugin to support create JSON string in an single expression.

    <img src="http://i1081.photobucket.com/albums/j352/rexrainbow1/FnHash.png" border="0">

  • Hi - Gonna res this thread because I'm getting a bit lost without named parameters.

    How about a compromise? Let us set a note when we create a new function, where we can key in a description of what we want the parameters to be.

    Then function call can show this note - if it detects one was set for the function name you key in.

    I've kind of tried to do this with comments, but my functions are sat in one sheet and it is niggly to toggle between where I am to remind myself of what I need to do.

    Also whilst I'm here, is there no way to make function call detect if the function name is invalid? Or even bring a drop down of the function names you are using?

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