Skip to Main Content
Construct 3 suggestions 21H2 - ARCHIVED

This suggestions platform is now closed and will be shut down on March 1st 2024.

Please ensure any content you care about is backed up before that date.

Feature requests are now handled on GitHub here: https://github.com/Scirra/Construct-feature-requests

6 VOTE
Categories Plugins
Created by ReflextionsDev
Created on Jun 16, 2022

Optional function parameters and better default values

There are frequently situations where all function parameters are not needed, it can be annoying to specify each one and it clutters workflow.

As an example, imagine a money formatting function with the parameters (money, symbol). Money is required, but perhaps symbol should default to "$". It is possible to provide default values, but they do not autofill for functions with return values. If the 'symbol' parameter was specified as optional, the user would not have to type out the symbol everytime, and it would be easier to have consistency where the function is called. The default symbol parameter could be changed rather than having to modify every money formatting function.

Additionally, default values are not dynamic: if the default value in a function is changed it does not update function calls that previously used the default value. This is because those parameters do not actually reference the specified default value but use a deep copy. This could be misleading to users.

I imagine a few ways this could be implemented.

  1. The user defines parameters as optional using a checkbox in the 'Add function parameter' menu.

    1. For functions with return values, the parameters do not need to be defined. They will default to the specified values when not defined.

    2. Additionally, all references to this parameters should italicized to distinguish it as optional. There could also be a visual distinction between required and optional parameters below functions via a "*" symbol, different background color, or something else.

    3. Optional parameters should always come last. They are order after required parameters, and then follow the users defined order. You could also enforce this in the editor by automatically sorting them like this.

  2. Any parameter with a defined default value would automatically be treated as optional. The same rules as above would apply, but defining params as optional would be automatic instead of manual.

  3. A hybrid of 1 and 2. Parameters would automatically be set as optional when a default value is provided, but the user can override this to make a function required but also provide a default value. I'm not sure this would be necessary.

I believe this can work as an elegant solution to both problems defined. It would also work to enforce default value consistency across all function calls. Please see the attachments below for some mockups of how this could look. Thanks.

  • Attach files
  • +4