"too many parameters passed to function" . . . return?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
chipy
Posts: 7
Joined: 29 Nov 2017, 23:43
Contact:

"too many parameters passed to function" . . . return?

Post by chipy » 26 Nov 2019, 20:38

I'm sorry if this should be in the bug-reports section, if so please let me know or move it for me, however it pertains directly to v2 alpha AHK.

While debugging a massive script I made a while back to work on the latest version of AHKv2 I've gotten stuck on this issue. I seem to be triggering some error possibly in the language or maybe I'm missing something obvious? I first got this error and as you can see in the screenshot it was pointing to "return" and I wasn't sure how return could accept params but then I got the same error here and cut out all the code I could and the error persists.

I'm testing/rebuilding this script in AHK 2.0-a106-4a6b3ff1. There might be an update for this already if so my apologies. I'm looking for someone more knowledgeable in AHK to take a quick look to see if it's something that could be fixed or if I simply need to rewrite the module. Thanks for your time in advance community.

Code: Select all

MasterSettings(){

	SettingsGUIID := GuiCreate(,"Settings")
	SettingsGUIID.setfont("s12", "open sans")
	ltext:=SettingsGUIID.add("text","xm w250","Settings").setfont("s14 bold", "Helvetica")

	;general settings
	SettingsTab := SettingsGUIID.add("tab3",,"General||ActionWheelTool(BETA)|Addional Module Installer|Setup/Help|About")

	SettingsTab.UseTab()
	SettingsGUIID.add("button",,"Cancel").OnEvent("Click",() => GUIClose())
	SettingsGUIID.OnEvent("close",() => GUIClose(SettingsGUIID))
	SettingsGUIID.show()	

	Return
}

GUIClose(args*){
	args[1].Destroy
	if(A_IsPaused)
		Pause "off"
	Suspend "off"

	Return
}


MsgBox "running: " A_AhkVersion "`nchipy used: 2.0-a106-4a6b3ff1"
mastersettings()
Attachments
AutoHotkey_FDUjAbujxu.png
AutoHotkey_FDUjAbujxu.png (8.12 KiB) Viewed 4126 times
AutoHotkey_8wNvn3luQV.png
AutoHotkey_8wNvn3luQV.png (9.11 KiB) Viewed 4126 times

User avatar
kczx3
Posts: 1648
Joined: 06 Oct 2015, 21:39

Re: "too many parameters passed to function" . . . return?

Post by kczx3 » 26 Nov 2019, 21:15

https://lexikos.github.io/v2/docs/Functions.htm#Variadic

See the third paragraph of this section. Your fat arrow functions need to have an asterisk in the parenthesis if you don’t care about the passed parameters.


chipy
Posts: 7
Joined: 29 Nov 2017, 23:43
Contact:

Re: "too many parameters passed to function" . . . return?

Post by chipy » 27 Nov 2019, 11:40

thanks guys! i'll look into these tonight tonight

chipy
Posts: 7
Joined: 29 Nov 2017, 23:43
Contact:

Re: "too many parameters passed to function" . . . return?

Post by chipy » 27 Nov 2019, 11:56

as per:
As best as i can understand, there needs to be an asterisk to indicate that we don't care about the extras params being passed around? In any event that seems to have fixed the issue, however, I am still a little confused about what "() =>" actually does and why simply putting "args*" for unlimited number of params wasn't enough. If anyone knows where i should go looking, searching for that code-phrase has been less than helpful because i don't know what "() =>" is actually called or does. ( the problem with using smarter people's suggestions :D ) Thanks again for everyone's help, and @SALZ and @xcc in discord you guys have all super helpful.

Code: Select all


MasterSettings(){
        ;creates gui
	SettingsGUIID := GuiCreate(,"Settings")
	SettingsGUIID.setfont("s12", "open sans")
	ltext:=SettingsGUIID.add("text","xm w250","Settings").setfont("s14 bold", "Helvetica")

	;create tabs
	SettingsTab := SettingsGUIID.add("tab3",,"General||ActionWheelTool(BETA)|Addional Module Installer|Setup/Help|About")

	SettingsTab.UseTab()
;added '*' to the two lines below to tell them to ignore extra params?
	SettingsGUIID.add("button",,"Cancel").OnEvent("Click",(*) => GUIClose(SettingsGUIID))
	SettingsGUIID.OnEvent("close",(*) => GUIClose(SettingsGUIID))
	SettingsGUIID.show()	

	Return
}

GUIClose(args*){
	args[1].Destroy()
	Return
}


MsgBox "running: " A_AhkVersion "`nchipy used: 2.0-a106-4a6b3ff1"
mastersettings()

guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: "too many parameters passed to function" . . . return?

Post by guest3456 » 27 Nov 2019, 12:22

chipy wrote:
27 Nov 2019, 11:56
however, I am still a little confused about what "() =>" actually does and why simply putting "args*" for unlimited number of params wasn't enough. If anyone knows where i should go looking, searching for that code-phrase has been less than helpful because i don't know what "() =>" is actually called or does.
a lot of people are confused with this new error

as for () => thats a fat-arrow function, it allows you to define an in-line function on the spot. in this case, you're simply using it as an alias for your other GUIclose() func. and your fat-arrow func is specified with 0 params (), but each of your OnEvent callbacks are trying to pass the appropriate number of params, but your fat arrow isn't allowing it. if you use (a) for one param it will work for the Close event. but it will fail for the OnClick event, because as you can see from that link, the OnClick event passes two params, so you'd need to do (x,y) etc. but you can just use * for an arbitrary number of params, since you are discarding them anyway and not using them.


chipy
Posts: 7
Joined: 29 Nov 2017, 23:43
Contact:

Re: "too many parameters passed to function" . . . return?

Post by chipy » 27 Nov 2019, 18:30

guest3456 wrote:
27 Nov 2019, 12:22
chipy wrote:
27 Nov 2019, 11:56
however, I am still a little confused about what "() =>" actually does and why simply putting "args*" for unlimited number of params wasn't enough. If anyone knows where i should go looking, searching for that code-phrase has been less than helpful because i don't know what "() =>" is actually called or does.
a lot of people are confused with this new error

as for () => thats a fat-arrow Broken Link for safety function, it allows you to define an in-line function on the spot. in this case, you're simply using it as an alias for your other GUIclose() func. and your fat-arrow func is specified with 0 params (), but each of your OnEvent callbacks are trying to pass the appropriate Broken Link for safety number of params, but your fat arrow isn't allowing it. if you use (a) for one param it will work for the Close event. but it will fail for the OnClick event, because as you can see from that link, the OnClick event passes two params, so you'd need to do (x,y) etc. but you can just use * for an arbitrary number of params, since you are discarding them anyway and not using them.
thanks a lot for your help! This explained what

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: "too many parameters passed to function" . . . return?

Post by swagfag » 28 Nov 2019, 12:06

as it is, ur GUIClose function is superfluous

Code: Select all

SettingsGUIID.add("button",,"Cancel").OnEvent("Click", (Ctrl, Info) => Ctrl.Gui.Destroy())
SettingsGUIID.OnEvent("close", Gui => Gui.Destroy())
should suffice

look what parameters various events may inject here

otherwise make it generic:

Code: Select all

SettingsGUIID.add("button",,"Cancel").OnEvent("Click", 'GuiClose')
SettingsGUIID.OnEvent("close", 'GuiClose')

...

GuiClose(Obj, *) {
	if Obj is 'Gui'
		Obj.Destroy()
	else
		Obj.Gui.Destroy()
}

Post Reply

Return to “Ask for Help (v2)”