I can’t think of how this can be possible, but it would be convenient for me. Currently, calling a Function must have the exact correct number of parameters. Is there a way to set up so a Function can have optional parameters? I can only think of encasing all the parameters in a single array, therefore there is ONE parameter, and just varying what I include in the array.
Yep, that’s a good way. I do this all the time, mostly to run the same function repeatedly with different parameters.
params = { x:1, y:2, title:“This!”}
myFunction (varr, m, params)
local = params.x
I assume you really mean “optional”, not just a parameter with a default value, although I can’t really see the difference.
Sub mySub(parm1 as String, parm2=invalid)
if parm2 <> invalid then
'do something
end if
'do more stuff
End Sub
mySub("hello")
mySub("hello","world")
-JT
“renojim” wrote:
I assume you really mean “optional”, not just a parameter with a default value, although I can’t really see the difference.
Right, it’s “the same difference” :). One can declare default values for some at the end of the list of arguments - and can check for default value as a flag if it was omitted. In other lagnguages (e.g. Lua) this is so idiomatic that does not have to spec it - if a function is called will less than the declared arguments, the rest are padded withnil(AKA null, invalid). This can be argued double-edged sword.
Coming from other scripting languages - like say Python - you would have heard the above approach as “default argument values”. Another approach of Keyword Arguments can easily be simulated in BrS by passing a dictionary with key-value pairs.
Wow, I just got to test that out, that’s exactly what I was talking about, and it’s something I didn’t know about due to still be a newbie! Thanks! ![]()
