I program in one other language that allows you to use expressions as optional parameters. It's a very cool feature, although in practice I don't use it as much as you would think - maybe 2-3% of my functions. The technique shown above works well.
What I usually do is reserve a special word like NADA to mean that the paramter wasn't passed, and compare to that. Using 0 or blank doesn't work because quite a bit of the time you actually want to pass a zero or blank as the real value. So I'd code your function as:
Code: Select all
CalcFontSize(txt,fWd:="NADA",fHt:="NADA") {
fWd := (fWd != "NADA" ? fWd : A_ScreenWidth)
fHt := (fHt != "NADA" ? fHt : A_ScreenHeight)
Of course, in cases where 0 is never a valid answer, you can simplify it to something like:
Code: Select all
CalcFontSize(txt,fWd:="",fHt:="") {
fWd := (fWd ? fWd : A_ScreenWidth)
fHt := (fHt ? fHt : A_ScreenHeight)