Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Optional arguments, arrays

Featured Replies

  • Newbies

The SMRegisterFunction has been the best thing in the world. It cuts execution time a ton over v1, not to mention script complexity.

However, I got to thinking about whether or not a function might not be registered with a optional argument. My groovy would need to check if a variable is defined, but it would allow for a function "library" to be updated, with the new arguments being optional. So long as sane defaults are set when nothing is declared, the "library" could be updated without any effect on old solutions. ie. no need to update everywhere.

The second thought, was whether pseudo-arrays like in FileMaker's Substitute function - Substitute( text ; searchString ; replaceString {; [searchString ; replaceString]}) - might not be possible. Maybe the arguments get put out as an array, or as a string buffer.

Just a cursory attempt seems to indicate a no, and it isn't the only way to go about things for sure.

If there is a way to do this, that would be great. If not, then maybe it is something to think about in a future version of ScriptMaster. Certainly, ScriptMaster has already been an invaluable tool.

ScriptMaster doesn't currently support optional arguments, although in theory it would be possible to have a compiled script accept variable/unlimited numbers of arguments. It's not clear how you'd access those items from your script, however, as they wouldn't be named parameters/variables. Maybe have a named parameter which gets converted to an array or List.

SMRegisterGroovy("Foo ( url ; args... )" ; $functionBody )

Something to think about... thanks for the suggestion!

What sort of things would you use this for?

  • Author
  • Newbies

Thanks for the response.

As far as optional arguments, I was thinking mostly a way to "future proof" a library full of groovy code. A function could be updated and the new arguments could be optional.

A new function could be added, but it would be nice to update the library and call some sane defaults for missing values from solutions (or pieces of solutions) that haven't been updated yet, while avoiding proliferation of functions.

Also, there is just the idea of having default values like port numbers in an email function.

As for lists, it would just be nice to deal with arrays for things like attachments or information that might accidentally contain common text delimiters. Of course, the delimiters can be substituted out before building the list, and then back in during processing in Groovy. That just means some massaging of data beforehand that would be nice to avoid.

There aren't any deal-breakers to be sure. ScriptMaster allows for things that were impossible or impractical before. These were just some of the first things I thought of when using v2 of the plug-in.

Thanks again for the suggestions.

  • 1 month later...

The future-proofing is a very good argument. I think we could use a specialized naming convention for the SMRegisterGroovy signature to denote optional elements:

SMRegisterGroovy("Foo ( url ; data { ; optionalArg1 ; optionalArg2 } )" ; $functionBody )

Anything after the opening curly bracket would be considered an optional argument.

I'll work on adding this in to ScriptMaster, please send me any suggestions.

  • 2 years later...

I would love to have this feature in ScriptMaster. Was this feature ever added? If not, are there plans to add it?

ScriptMaster does not currently support optional parameters.

Are there any plans to support optional parameters?

It's on our list of things to do for ScriptMaster, but I definitely do not have a date for you.

  • 1 month later...

Is there anything I can do to help add this feature? I could possibly write some code to implement this, or a part of it.

I think this would be a great addition to ScriptMaster, and I would definitely use it in my plug-in project: https://github.com/dansmith65/ooScriptMaster

We could do this for you as a custom development project for you. Our rate is $165/hour. If you're interested, send an email to [email protected] and we can get you a quote.

Sorry, I don't have the funds for that. All I can offer is my own development time.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.