[a103] Bug? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
irral
Posts: 6
Joined: 14 May 2019, 02:38

[a103] Bug?

Post by irral » 05 Jul 2019, 04:15

Hi there!
I'm trying to make a hotkey, which activates only if the foo() and bar() functions returns a non-zero value.
The Hotkey "If", FunctionObject should help solve the problem, but if I press a hotkey in this example it will result in an error.

Code: Select all

#SingleInstance force
#Persistent
#UseHook

boo( () => (foo() && bar()) )
return ; end of autoexec section

boo(a)
{
	b := Func("baz").bind("test")
	Hotkey "If", a
	Hotkey "vk31", b ; 1 key
}

foo()
{
	return 1
}

bar()
{
	return 0
}

baz(a)
{
	MsgBox a
}
Error
Why the hotkey activates despite the fact that bar() returns 0?
What is the reason of error? The arrow points to return on the end of autoexecute section and I'm nowhere passing params more than necessary.
Thanks!
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [a103] Bug?  Topic is solved

Post by Helgef » 05 Jul 2019, 04:38

It is not a bug, the documentation is not up to date.
The function object is passed the name of the hotkey,
Hotkey if wrote: The function or call method can accept one parameter: the name of the hotkey.
and since a103,
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.
So the solution is to define the parameter or use the star (*) to allow surplus parameters. Eg, (*) => (foo() && bar()).

Cheers.
Post Reply

Return to “Ask for Help (v2)”