Blank parameter error Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
helming
Posts: 25
Joined: 07 Dec 2016, 15:01

Blank parameter error

29 Jan 2021, 00:26

Hello, guys

Code: Select all

MyFunc(1,, 3)
MyFunc(X, Y:=2, Z:=0) {  ; Note that Z must still be optional in this case.
    MsgBox %X%, %Y%, %Z%
}
This is a sample code from https://www.autohotkey.com/docs/Functions.htm

It works fine.

Code: Select all

f7::MyFunc(1,5, )
MyFunc(X, Y:=2, Z:=0) {  ; Note that Z must still be optional in this case.
    MsgBox %X%, %Y%, %Z%
}
This script cause a error of blank parameter.
Third parameter(Z) is optional parameter like second parameter(Y), so why is it a problem?
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Blank pararmeter error

29 Jan 2021, 01:28

Code: Select all

F7::MyFunc(1,5)
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Re: Blank pararmeter error  Topic is solved

29 Jan 2021, 03:32

If you want to use the default value of the 2nd parameter but specify the 3rd, you need to let ahk know that explicitly by leaving one argument empty.
If you want to use the default value of the 3rd parameter you should omit it entirely, i.e. not place a comma after the 2nd argument when calling.

One of many inconsistencies in AHK but they're the things that make the language so lovable!
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Blank pararmeter error

29 Jan 2021, 07:11

Thanks for explaining it (my neglect)!
helming
Posts: 25
Joined: 07 Dec 2016, 15:01

Re: Blank parameter error

30 Jan 2021, 23:05

All right, I can see now!

Thank you Pepineros, and Mikey!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Hugh Jars, Mateusz53, MrDoge, peter_ahk and 369 guests