OnExit() bug Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
guest3456
Posts: 3469
Joined: 09 Oct 2013, 10:31

OnExit() bug

Post by guest3456 » 19 Jun 2019, 10:08

Code: Select all

OnExit("ExitFunc")
MsgBox("Press ESC")
ESC::ExitApp

ExitFunc()
{
   MsgBox("press OK to exit")
}
Error "too many params passed to func"

There is certainly not too many, but maybe too few..

docs:
https://lexikos.github.io/v2/docs/commands/OnExit.htm wrote: The function can optionally define parameters as shown below.
...
If an OnExit function declares parameters, its first parameter is one of the following words:

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: OnExit() bug

Post by Helgef » 19 Jun 2019, 10:36

The documentation is not up to date, the error is intended.
a103 wrote:Changed function calls to throw if too many parameters are passed.
Added fn(a,*) as a means to permit but not store surplus parameters.
Cheers.
guest3456
Posts: 3469
Joined: 09 Oct 2013, 10:31

Re: OnExit() bug

Post by guest3456 » 19 Jun 2019, 11:11

Helgef wrote:
19 Jun 2019, 10:36
The documentation is not up to date, the error is intended.
a103 wrote:Changed function calls to throw if too many parameters are passed.
Added fn(a,*) as a means to permit but not store surplus parameters.
Cheers.
i dont get it. if anything, too FEW are passed. what am i missing? what should my code look like?

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

Re: OnExit() bug  Topic is solved

Post by swagfag » 19 Jun 2019, 11:18

OnExit passes ExitReason, ExitCode and whatever other parameters u might have bound
ur onexit handler accepts 0 parameters, change it to ExitFunc(*) if want to ignore any parameters that have been passed to it
guest3456
Posts: 3469
Joined: 09 Oct 2013, 10:31

Re: OnExit() bug

Post by guest3456 » 19 Jun 2019, 12:34

swagfag wrote:
19 Jun 2019, 11:18
OnExit passes ExitReason, ExitCode and whatever other parameters u might have bound
ur onexit handler accepts 0 parameters, change it to ExitFunc(*) if want to ignore any parameters that have been passed to it
ok thanks

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

Re: OnExit() bug

Post by kczx3 » 20 Jun 2019, 20:14

This change continues to be a problem for people it seems
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: OnExit() bug

Post by nnnik » 28 Jun 2019, 05:39

Yeah people got used to omitting parameters on the function definition because AHK never threw errors.
I expected that people would have issues while in the transition and blame AHK rather than look for a change in AHK that requires them to fix their now flawed code.
People didnt have to consider these points before - now they have to consider the amount of parameters a function gives (or just use *).

I can imagine that it is an annoyance when moving forth and will be difficult adjusting to at first.
However as a longterm user the amount of time I spend finding bugs with too many too few parameters probably exceeds the amount of time newbies take to learn the language.
This change had to be made.
Recommends AHK Studio
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: OnExit() bug

Post by Helgef » 28 Jun 2019, 07:10

It seems that the outdated documentation is the problem though, I think once that is fixed this won't be much of an issue. guest3456 did the right thing, he looked in the docs, however, since v2 is not complete, it isn't completely reliable. Also note that it is possible that these callback functions can have optional parameters in the future, the program isn't required to pass an excessive amount of parameters, at least not when maxparams is available.

Cheers.
Post Reply

Return to “Ask for Help (v2)”